String routines to complement <string> && <cstring>:
string_tool.h
Go to the documentation of this file.
1 // string_tool.h (C) 2012 adolfo@di-mare.com
2 
3 /** \file string_tool.h
4  \brief Rutinas de hileras que complementan
5  \c <string> y \c <cstring>.
6  \author Adolfo Di Mare <adolfo@di-mare.com>
7  \date 2012
8 */
9 
10 #ifndef string_tool_h
11 #define string_tool_h
12 
13 /// Rutinas \c string_tool.h de hileras que complementan
14 /// \c <string> y \c <cstring>.
15 struct string_tool{}; ///< - Truco -> Doxygen lo saca como clase
16 
17 #include <list> // std::list
18 #include <string> // std::string
19 #include <cstring> // std::strlen()
20 
21 void tolower( std::string& line );
22 void trimQuote( std::string& word );
23 bool isalpha( const std::string& line );
24 bool is_blank( const std::string& word );
25 bool issuffix( const char* str, const char* suffix );
26 
27 unsigned digitCount( const std::string& str , unsigned i );
28 unsigned alphaCount( const std::string& str , unsigned i );
29 unsigned number_suffix( const std::string& str );
30 unsigned str2uint( const std::string& str );
31 std::string tostring( unsigned n, unsigned width );
32 void tostring( unsigned N, unsigned width, char *str );
33 char *strdel(char *str, size_t from, size_t len);
34 char *strdel2(char *str, size_t len);
35 
36 /// Retorna \c true si \c es uno de { '-' '_' '~' }.
37 inline bool isdash( char c ) { return c=='-' || c=='_' || c=='~'; }
38 
39 /** Retorna \c true si \c ch es un caracter son letras
40  que pueden aparecer en una dirección email.
41  - Es equivalente a
42  <code>( isalpha(ch) || ch=='-' || ch=='.' || ch=='_' )</code>
43 
44  \dontinclude string_tool_test.cpp
45  \skipline test::is_email()
46  \until }}
47 */
48 inline bool is_email( char ch ) {
49  return ( isalpha(ch) || ch=='-' || ch=='.' || ch=='_' );
50 }
51 
52 // Accented conversion table
53 #define A_TILDE_64 \
54  "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
55 #define A_SIMPLE_64 \
56  "AAAAAAECEEEEIIIIDNOOOOOx0UUUUYPsaaaaaaeceeeeiiiiOnooooo/0uuuuypy"
57 
58 char removeAccented( char ch );
59 const char* removeAccented( char* str );
60 const std::string& removeAccented( std::string& str );
61 
62 void tokens(
63  const std::string& renglon,
64  std::list<std::string>& L,
65  const char* delimiters
66 );
67 
68 #endif // string_tool_h
69 
70 // EOF: string_tool.h
digitCount
unsigned digitCount(const std::string &str, unsigned i)
Retorna la cantidad de dígitos consecutivos a partir de str[i].
Definition: string_tool.cpp:209
removeAccented
char removeAccented(char ch)
Retorna la letra sin acento que corresponde a ch.
Definition: string_tool.cpp:39
issuffix
bool issuffix(const char *str, const char *suffix)
Verifica si suffix es un sufijo de str.
Definition: string_tool.cpp:172
number_suffix
unsigned number_suffix(const std::string &str)
Retorna el número que está al final de str.
Definition: string_tool.cpp:248
is_blank
bool is_blank(const std::string &word)
Retorna true si todos las caracteres en word son blancos.
Definition: string_tool.cpp:157
tokens
void tokens(const std::string &renglon, std::list< std::string > &L, const char *delimiters)
Separa las palabras de 'renglon' y las deja en la lista 'L'.
Definition: string_tool.cpp:348
alphaCount
unsigned alphaCount(const std::string &str, unsigned i)
Retorna la cantidad de letras consecutivas a partir de 'str[i]'.
Definition: string_tool.cpp:229
isdash
bool isdash(char c)
Retorna true si es uno de { '-' '_' '~' }.
Definition: string_tool.h:37
isalpha
bool isalpha(const std::string &line)
Regresa true si todos los caracteres de line son alfabéticos.
Definition: string_tool.cpp:140
strdel2
char * strdel2(char *str, size_t len)
Deletes 'len' chars from the start of 'str'.
Definition: string_tool.cpp:407
tostring
std::string tostring(unsigned n, unsigned width)
Retorna la hilera que contiene los últimos 'width' dígitos de 'N'.
Definition: string_tool.cpp:304
tolower
void tolower(std::string &line)
Convierte a minúscula todas las letras de line.
Definition: string_tool.cpp:19
string_tool
Rutinas string_tool.h de hileras que complementan <string> y <cstring>.
Definition: string_tool.h:15
trimQuote
void trimQuote(std::string &word)
Elimina comillas ['] ["] del principio o final de 'word'.
Definition: string_tool.cpp:121
strdel
char * strdel(char *str, size_t from, size_t len)
Deletes 'len' chars from 'str' starting at index 'from'.
Definition: string_tool.cpp:384
is_email
bool is_email(char ch)
Retorna true si ch es un caracter son letras que pueden aparecer en una dirección email.
Definition: string_tool.h:48
str2uint
unsigned str2uint(const std::string &str)
Convierte 's' un número entero sin signo.
Definition: string_tool.cpp:274