Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Utilities.h File Reference
#include "Stroika/Foundation/StroikaPreComp.h"
#include <cstdarg>
#include <cstring>
#include <string>
#include "Stroika/Foundation/Characters/Character.h"
#include "Stroika/Foundation/Common/Common.h"
#include "Utilities.inl"

Go to the source code of this file.

Namespaces

namespace  Stroika::Foundation
 
namespace  Stroika::Foundation::Characters
 

Functions

template<IPossibleCharacterRepresentation T>
size_t Stroika::Foundation::Characters::CString::Length (const T *p)
 Measure the length of the argument c-string (NUL-terminated string).
 
template<typename T >
bool Stroika::Foundation::Characters::CString::Equals (const T *lhs, const T *rhs)
 strcmp or wsccmp() as appropriate == 0
 
template<typename T >
void Stroika::Foundation::Characters::CString::Copy (T *dest, size_t nEltsInDest, const T *src)
 Safe variant of strncpy() - which always NUL-terminates the string.
 
template<typename T >
void Stroika::Foundation::Characters::CString::Cat (T *dest, size_t nEltsInDest, const T *src2Append)
 Safe variant of strncat() - which always NUL-terminates the string. DIFFERNT arguments however, so not safe direct substitution.
 
string Stroika::Foundation::Characters::CString::LimitLength (const string &str, size_t maxLen, bool keepLeft=true)
 
template<typename TCHAR >
basic_string< TCHAR > Stroika::Foundation::Characters::CString::LTrim (const basic_string< TCHAR > &text)
 
string Stroika::Foundation::Characters::CString::StripTrailingCharIfAny (const string &s, char c)
 
unsigned int Stroika::Foundation::Characters::CString::HexString2Int (const string &s)
 
template<typename T >
Stroika::Foundation::Characters::CString::String2Int (const string &s)
 

Detailed Description

Legacy "C_String" string utilities.

TODO:

Definition in file Characters/CString/Utilities.h.

Function Documentation

◆ Length()

template<IPossibleCharacterRepresentation T>
size_t Stroika::Foundation::Characters::CString::Length ( const T *  p)

Measure the length of the argument c-string (NUL-terminated string).

Measure the length of the argument c-string (NUL-terminated string). Overloaded version of strlen/wcslen.

Only implemented for char/wchar_t. Reason for this is so code using old-style C++ strings can leverage overloading!

Definition at line 17 of file Characters/CString/Utilities.inl.

◆ Copy()

template<typename T >
void Stroika::Foundation::Characters::CString::Copy ( T *  dest,
size_t  nEltsInDest,
const T *  src 
)

Safe variant of strncpy() - which always NUL-terminates the string.

Copy the C-string pointed to by 'src' to the location pointed to by 'dest'. 'nEltsInDest' - as the name suggests - is the number of elements in the array pointed to by 'dest' - not the max string length for 'dest.

This function will always nul-terminate, and it is illegal to call it with a value of zero for nEltsInDest.

This is basically like strcpy/strncpy, except with better logic for nul-termination.

Note - the arguments are not in exactly the same order as strncpy() - with the length of the buffer for the first string before the second string.

Example Usage
char urlBuf[1024];
CString::Copy (urlBuf, NEltsOf (urlBuf), url.c_str ());

Definition at line 100 of file Characters/CString/Utilities.inl.

◆ Cat()

template<typename T >
void Stroika::Foundation::Characters::CString::Cat ( T *  dest,
size_t  nEltsInDest,
const T *  src2Append 
)

Safe variant of strncat() - which always NUL-terminates the string. DIFFERNT arguments however, so not safe direct substitution.

Note - the arguments are not in exactly the same order as strncpy() - with the length of the buffer for the first string before the second string.

Definition at line 150 of file Characters/CString/Utilities.inl.

◆ LimitLength()

string Stroika::Foundation::Characters::CString::LimitLength ( const string &  str,
size_t  maxLen,
bool  keepLeft = true 
)
See also
String::LimitLength()

Definition at line 246 of file Characters/CString/Utilities.cpp.

◆ LTrim()

template<typename TCHAR >
basic_string< TCHAR > Stroika::Foundation::Characters::CString::LTrim ( const basic_string< TCHAR > &  text)
See also
String::LTrim()
String::RTrim()
String::Trim()

Definition at line 200 of file Characters/CString/Utilities.inl.

◆ StripTrailingCharIfAny()

string Stroika::Foundation::Characters::CString::StripTrailingCharIfAny ( const string &  s,
char  c 
)

This could be generalized to accomodate TRIM/merge with TRIM, but it sometimes used to trim other characters (like trailing CRLF, or trailing '.').

Definition at line 274 of file Characters/CString/Utilities.cpp.

◆ HexString2Int()

unsigned int Stroika::Foundation::Characters::CString::HexString2Int ( const string &  s)

Convert the given hex-format string to an unsigned integer. String2Int will return 0 if no valid parse, and UINT_MAX on overflow.

See also
strtoul(), or
wcstol (). This is a simple wrapper on strtoul() or wcstoul(). strtoul() etc are more flexible. This is merely meant to be an often convenient wrapper. Use strtoul etc directly to see if the string parsed properly.

Definition at line 289 of file Characters/CString/Utilities.cpp.

◆ String2Int()

template<typename T >
T Stroika::Foundation::Characters::CString::String2Int ( const string &  s)

Convert the given decimal-format integral string to any integer type ( e.g. signed char, unsigned short int, long long int, uint32_t etc).

String2Int will return 0 if no valid parse, and numeric_limits<T>::min on underflow, numeric_limits<T>::max on overflow.

CONSIDER!

See also
strtoll(), or
wcstoll (). This is a simple wrapper on strtoll() / wcstoll (). strtoll() is more flexible. This is merely meant to be an often convenient wrapper. Use strtoll etc directly to see if the string parsed properly.

Definition at line 281 of file Characters/CString/Utilities.inl.