Alternative 7-bit upper- and lowercase

develop
kaetemi 4 years ago
parent 73b8ba9e4e
commit ffa6179b82

@ -267,6 +267,18 @@ void toLowerAscii(char *str, char replacement);
std::string toUpperAscii(const std::string &str, char replacement);
void toUpperAscii(char *str, char replacement);
/** ASCII to lowercase. Useful for internal identifiers.
* Characters outside of the 7-bit ASCII space are not affected.
*/
std::string toLowerAscii(const std::string &str);
void toLowerAscii(char *str);
/** ASCII to uppercase. Useful for internal identifiers.
* Characters outside of the 7-bit ASCII space are not affected.
*/
std::string toUpperAscii(const std::string &str);
void toUpperAscii(char *str);
/**
* Convert to an hexadecimal std::string
*/

@ -577,7 +577,6 @@ uint32 fromHumanReadable (const std::string &str)
return 0;
}
NLMISC_CATEGORISED_COMMAND(nel,stohr, "Convert a second number into an human readable time", "<int>")
{
nlunreferenced(rawCommandString);
@ -594,6 +593,50 @@ NLMISC_CATEGORISED_COMMAND(nel,stohr, "Convert a second number into an human rea
return true;
}
NLMISC_CATEGORISED_COMMAND(nel, toLower, "Convert a string to lowercase", "<string>")
{
nlunreferenced(args);
nlunreferenced(quiet);
nlunreferenced(human);
log.displayNL("%s", toLower(rawCommandString).c_str());
return true;
}
NLMISC_CATEGORISED_COMMAND(nel, toUpper, "Convert a string to uppercase", "<string>")
{
nlunreferenced(args);
nlunreferenced(quiet);
nlunreferenced(human);
log.displayNL("%s", toUpper(rawCommandString).c_str());
return true;
}
NLMISC_CATEGORISED_COMMAND(nel, toLowerAscii, "Convert a string's ascii-characters to lowercase", "<string>")
{
nlunreferenced(args);
nlunreferenced(quiet);
nlunreferenced(human);
log.displayNL("%s", toLowerAscii(rawCommandString).c_str());
return true;
}
NLMISC_CATEGORISED_COMMAND(nel, toUpperAscii, "Convert a string's ascii-characters to uppercase", "<string>")
{
nlunreferenced(args);
nlunreferenced(quiet);
nlunreferenced(human);
log.displayNL("%s", toUpperAscii(rawCommandString).c_str());
return true;
}
#if 0
std::string toLower(const char *str)
@ -739,6 +782,52 @@ void toUpperAscii(char *str, char replacement)
}
}
std::string toLowerAscii(const std::string &str)
{
std::string res;
res.reserve(str.size());
for (std::string::const_iterator it(str.begin()), end(str.end()); it != end; ++it)
{
char c = *it;
if (c >= 'A' && c <= 'Z') res += c + ('a' - 'A');
else res += c;
}
return res;
}
void toLowerAscii(char *str)
{
for (ptrdiff_t i = 0; str[i]; ++i)
{
char c = str[i];
if (c >= 'A' && c <= 'Z') str[i] = c + ('a' - 'A');
else str[i] = c;
}
}
std::string toUpperAscii(const std::string &str)
{
std::string res;
res.reserve(str.size());
for (std::string::const_iterator it(str.begin()), end(str.end()); it != end; ++it)
{
char c = *it;
if (c >= 'a' && c <= 'z') res += c - ('a' - 'A');
else res += c;
}
return res;
}
void toUpperAscii(char *str)
{
for (ptrdiff_t i = 0; str[i]; ++i)
{
char c = str[i];
if (c >= 'a' && c <= 'z') str[i] = c - ('a' - 'A');
else str[i] = c;
}
}
std::string toHexa(const uint8 &b)
{
return toString("%02hhx", b);

Loading…
Cancel
Save