Some conversion functions.
More...
#include "utilite/UtiLiteExp.h"
#include <string>
#include <vector>
#include <stdarg.h>
Go to the source code of this file.
Functions |
std::string UTILITE_EXP | uReplaceChar (const std::string &str, char before, char after) |
std::string UTILITE_EXP | uReplaceChar (const std::string &str, char before, const std::string &after) |
std::string UTILITE_EXP | uToUpperCase (const std::string &str) |
std::string UTILITE_EXP | uToLowerCase (const std::string &str) |
std::string UTILITE_EXP | uNumber2Str (unsigned int number) |
std::string UTILITE_EXP | uNumber2Str (int number) |
std::string UTILITE_EXP | uNumber2Str (float number) |
std::string UTILITE_EXP | uNumber2Str (double number) |
std::string UTILITE_EXP | uBool2Str (bool boolean) |
bool UTILITE_EXP | uStr2Bool (const char *str) |
std::string UTILITE_EXP | uBytes2Hex (const char *bytes, unsigned int bytesLen) |
std::vector< char > UTILITE_EXP | uHex2Bytes (const std::string &hex) |
std::vector< char > UTILITE_EXP | uHex2Bytes (const char *hex, int hexLen) |
std::string UTILITE_EXP | uHex2Str (const std::string &hex) |
unsigned char UTILITE_EXP | uHex2Ascii (const unsigned char &c, bool rightPart) |
unsigned char UTILITE_EXP | uAscii2Hex (const unsigned char &c) |
std::string UTILITE_EXP | uFormatv (const char *fmt, va_list ap) |
std::string UTILITE_EXP | uFormat (const char *fmt,...) |
Detailed Description
Some conversion functions.
This contains functions to do some convenient conversion like uNumber2str(), uBytes2Hex() or uHex2Bytes().
Function Documentation
unsigned char UTILITE_EXP uAscii2Hex |
( |
const unsigned char & |
c | ) |
|
Convert an ascii character to an hexadecimal value (right 4 bits). Characters can be in upper or lower case. Example :
unsigned char hex = uAscii2Hex('F');
- See also:
- hex2ascii
- Parameters:
-
- Returns:
- the hexadecimal value
std::string UTILITE_EXP uBool2Str |
( |
bool |
boolean | ) |
|
Convert a bool to a string. The format used is "true" and "false".
- Parameters:
-
boolean | the boolean to convert in a string |
- Returns:
- the string
std::string UTILITE_EXP uBytes2Hex |
( |
const char * |
bytes, |
|
|
unsigned int |
bytesLen |
|
) |
| |
Convert a bytes array to an hexadecimal string. The resulting string is twice the size of the bytes array. The hexadecimal Characters are in upper case. Example :
char bytes[] = {0x3F};
std::string hex = uBytes2Hex(bytes, 1);
- Parameters:
-
bytes | the bytes array |
bytesLen | the length of the bytes array |
- Returns:
- the hexadecimal string
std::string UTILITE_EXP uFormat |
( |
const char * |
fmt, |
|
|
|
... |
|
) |
| |
Format a string like printf, and return it as a std::string
std::string UTILITE_EXP uFormatv |
( |
const char * |
fmt, |
|
|
va_list |
ap |
|
) |
| |
Format a string like printf, and return it as a std::string
unsigned char UTILITE_EXP uHex2Ascii |
( |
const unsigned char & |
c, |
|
|
bool |
rightPart |
|
) |
| |
Convert hexadecimal (left or right part) value to an ascii character. Example :
unsigned char F = uHex2Ascii(0xFA, false);
unsigned char A = uHex2Ascii(0xFA, true);
- See also:
- ascii2hex
- Parameters:
-
c | the hexadecimal value |
rightPart | If we want the character corresponding to the right of left part (4 bits) of the byte value. |
- Returns:
- the ascii character (in upper case)
std::vector<char> UTILITE_EXP uHex2Bytes |
( |
const std::string & |
hex | ) |
|
Convert an hexadecimal string to a bytes array. The string must be pair length. The hexadecimal Characters can be in upper or lower case. Example :
std::string hex = "1f3B";
std::vector<char> bytes = uHex2Bytes(hex);
- Parameters:
-
hex | the hexadecimal string |
- Returns:
- the bytes array
std::vector<char> UTILITE_EXP uHex2Bytes |
( |
const char * |
hex, |
|
|
int |
hexLen |
|
) |
| |
Convert an hexadecimal string to a bytes array. The string must be pair length. The hexadecimal Characters can be in upper or lower case. Example :
std::vector<char> bytes = uHex2Bytes("1f3B", 4);
- Parameters:
-
hex | the hexadecimal string |
bytesLen | the hexadecimal string length |
- Returns:
- the bytes array
std::string UTILITE_EXP uHex2Str |
( |
const std::string & |
hex | ) |
|
Convert an hexadecimal string to an ascii string. A convenient way when using only strings. The hexadecimal str MUST not contains any null values 0x00 ("00"). Think to use of hex2bytes() to handle 0x00 values. Characters can be in upper or lower case. Example :
std::string str = uHex2Str("48656C6C4F21");
- See also:
- hex2bytes
- Parameters:
-
hex | the hexadecimal string |
- Returns:
- the ascii string
std::string UTILITE_EXP uNumber2Str |
( |
unsigned int |
number | ) |
|
Convert a number (unsigned int) to a string.
- Parameters:
-
number | the number to convert in a string |
- Returns:
- the string
Convert a number (int) to a string.
- Parameters:
-
number | the number to convert in a string |
- Returns:
- the string
Convert a number (float) to a string.
- Parameters:
-
number | the number to convert in a string |
- Returns:
- the string
Convert a number (double) to a string.
- Parameters:
-
number | the number to convert in a string |
- Returns:
- the string
std::string UTILITE_EXP uReplaceChar |
( |
const std::string & |
str, |
|
|
char |
before, |
|
|
char |
after |
|
) |
| |
Replace old characters in a string to new ones. Example :
std::string str = "Hello";
uReplaceChar(str, 'l', 'p');
- Parameters:
-
str | the string |
before | the character to be replaced by the new one |
after | the new character replacing the old one |
- Returns:
- the modified string
std::string UTILITE_EXP uReplaceChar |
( |
const std::string & |
str, |
|
|
char |
before, |
|
|
const std::string & |
after |
|
) |
| |
Replace old characters in a string with the specified string. Example :
std::string str = "Hello";
uReplaceChar(str, 'o', "oween");
- Parameters:
-
str | the string |
before | the character to be replaced by the new one |
after | the new string replacing the old character |
- Returns:
- the modified string
bool UTILITE_EXP uStr2Bool |
( |
const char * |
str | ) |
|
Convert a string to a boolean. The format used is : "false", "FALSE" or "0" give false. All others give true.
- Parameters:
-
str | the string to convert in a boolean |
- Returns:
- the boolean
std::string UTILITE_EXP uToLowerCase |
( |
const std::string & |
str | ) |
|
Transform characters from a string to lower case. Example :
std::string str = "HELLO!";
str = uToLowerCase(str, false);
- Parameters:
-
- Returns:
- the modified string
std::string UTILITE_EXP uToUpperCase |
( |
const std::string & |
str | ) |
|
Transform characters from a string to upper case. Example :
std::string str = "hello!";
str = uToUpperCase(str);
- Parameters:
-
- Returns:
- the modified string