DATAKIT API  V2025.1
Dtk_string Class Reference

This is a high level string class. More...

Public Types

typedef size_t Size_t
 

Public Member Functions

const Dtk_WChar_t_w_str_us () const
 Retrieve the UNICODE string. More...
 
void add_int (const int integer, int force_unsigned_int=0)
 concat an int to the Dtk_string (convert the int to Dtk_string) More...
 
const char * c_str () const
 Retrieve the ASCII conversion string. More...
 
void cat (const Dtk_string &s2)
 concat the Dtk_string with the Dtk_string given in parameter More...
 
void clear ()
 clear string data More...
 
int cmp (const Dtk_string &s2) const
 compare the Dtk_string with the string given in parameter More...
 
int cmp (const Dtk_WChar_t *s2) const
 
void convert_from_int (const int integer, int force_unsigned_int=0)
 affectation operator from a int More...
 
void ConvertFromUTF8String (const char *inUTF8String)
 
int count_char_occurrences (const int car) const
 Counts all the occurrences of a given character into the Dtk_string. More...
 
int count_substring_occurrences (const Dtk_string &substring) const
 Counts all the occurrences of a given substring into the Dtk_string. More...
 
void cpy (Dtk_string s2)
 copy the Dtk_string given in parameter in the Dtk_string More...
 
Dtk_string drive () const
 File Utility : Retrieves the drive in Dtk_string form. More...
 
 Dtk_string ()
 Default constructor. More...
 
 Dtk_string (const char *s)
 constructor from a char * (ASCII string) More...
 
 Dtk_string (const char *s, const Dtk_Size_t &inCount)
 
 Dtk_string (const double dbl_val)
 constructor from a double More...
 
 Dtk_string (const double dbl_val, Dtk_Int32 inWithMorePrecision)
 
 Dtk_string (const Dtk_string &)
 copy constructor More...
 
 Dtk_string (const Dtk_WChar_t *s)
 
 Dtk_string (const float float_val)
 constructor from a float More...
 
 Dtk_string (Dtk_string &&s) DTK_NOEXCEPT
 Move constructor. More...
 
Dtk_bool existe_fichier () const
 File Utility : tests if a file exists. More...
 
Dtk_string extension () const
 File Utility : Retrieves the extension in Dtk_string form. More...
 
Dtk_string filename () const
 File Utility : Retrieves the filename in Dtk_string form. More...
 
void FileNameExtension (Dtk_string &outFileNameExtension) const
 File Utility : Retrieves the filename extension in Dtk_string form. More...
 
Dtk_Size_t FileSize () const
 File Utility : retrieve the file size. More...
 
int find_first (int character) const
 find the position of a character into a Dtk_string More...
 
int find_last (int character) const
 find the position of a character into a Dtk_string More...
 
int find_substring (const Dtk_string &s1) const
 find the position of a substring into a Dtk_string More...
 
void FixPathSeparator ()
 File Utility : Fixes path separator consistency. It lets you replace the '\' or '/' by the OS needed separator. More...
 
void free_mem ()
 
void FullPath (Dtk_string &outFullPath) const
 File Utility : Retrieves the full path in Dtk_string form. More...
 
Dtk_Size_t get_char (char *inoutStr) const
 copy the Dtk_string in a char * (ASCII) string More...
 
void get_wchar (Dtk_WChar_t *str) const
 copy the Dtk_string in a char * (UNICODE) string More...
 
int icmp (const Dtk_string &s2) const
 Perform a lowercase comparison of strings. More...
 
int icmp (const Dtk_WChar_t *s2) const
 
Dtk_bool is_not_NULL () const
 
Dtk_bool is_NULL () const
 
Dtk_string left (int pos) const
 retrieve the left part of the Dtk_string from a position More...
 
Dtk_string left_exclusive (int pos) const
 retrieve the left part of the Dtk_string from a position More...
 
void LeftExclusive (const int &pos, Dtk_string &outRes) const
 
int len () const
 Retrieve the length of the Dtk_string. More...
 
void Merge (const Dtk_string &s2)
 
int mkdir () const
 File Utility : Create a Directory. More...
 
int ncmp (const Dtk_string &s2, const int count) const
 compare the count first character of the Dtk_string with the string given in parameter More...
 
int ncmp (const Dtk_WChar_t *s2, const int count) const
 
void ncpy (const Dtk_string &s2, size_t size)
 copy a number of characters of the Dtk_string in an other Dtk_string More...
 
int nicmp (const Dtk_string &s2, const size_t size) const
 Compare characters of two strings without regard to case. More...
 
int nicmp (const Dtk_WChar_t *s2, const size_t size) const
 
FILE * OpenFile (const Dtk_string &inRights) const
 File Utility : Open a file with the given rights. More...
 
Dtk_stringoperator+= (const Dtk_string &s2)
 
Dtk_stringoperator= (const char *s)
 affectation operator from a char (ASCII) string More...
 
Dtk_stringoperator= (const double dbl_val)
 affectation operator from a double More...
 
Dtk_stringoperator= (const Dtk_string &s)
 affectation operator from a Dtk_string More...
 
Dtk_stringoperator= (const float fltval)
 affectation operator from a float More...
 
Dtk_stringoperator= (Dtk_string &&s) DTK_NOEXCEPT
 Move assignment operator. More...
 
const Dtk_WChar_toperator[] (int i) const
 
Dtk_WChar_toperator[] (int)
 access to a specified letter in the Dtk_string More...
 
FILE * ouvrir_fichier (const Dtk_string &droits) const
 File Utility : Open a file with the given rights. More...
 
Dtk_string path () const
 File Utility : Retrieves the path in Dtk_string form. More...
 
void RawCopyFromASCII (const char *inStrToBeCopied, const Dtk_Size_t inCount=-1)
 
int removechar (const int &removed_char)
 Removes all occurrences of a character in a string. More...
 
int replace (const int &old_char, const int &new_char)
 Replaces all occurrences of a character in a string with a new character. More...
 
Dtk_string right (int pos) const
 retrieve the right part of the Dtk_string from a position More...
 
Dtk_string right_exclusive (int pos) const
 retrieve the right part of the Dtk_string from a position More...
 
void RightExclusive (const int &pos, Dtk_string &outRes) const
 
int rmdir () const
 
 SetAsDeprecated ("2022.3", "Use FileSize() method instead") long taille_fichier() const
 
void Split (const Dtk_string &inDelimiters, Dtk_tab< Dtk_string > &outResults) const
 Split a Dtk_string into an array of Dtk_string giving a char array. More...
 
void Split (Dtk_WChar_t *inDelimiters, Dtk_tab< Dtk_string > &outResults) const
 
Dtk_string Substring (const Dtk_Size_t &inStartIndex, const Dtk_Size_t &inLength) const
 
int test_extension (const Dtk_string &ext) const
 
Dtk_status ToDtkDouble64 (Dtk_Double64 &outRes) const
 
Dtk_status ToDtkInt32 (Dtk_Int32 &outRes) const
 
void ToLower ()
 Converts the Dtk_string to Lower case. More...
 
void ToUpper ()
 Converts the Dtk_string to Upper case. More...
 
char * ToUTF8String () const
 Converts the Dtk_string to UTF8 string. More...
 
int traite_nom_fichier (Dtk_string *drive, Dtk_string *path, Dtk_string *filename, Dtk_string *extension) const
 File Utility: Splits Fullpath into drive/path/filename/extension. More...
 
void TrimCharacters (const Dtk_WChar_t inCharToBeTrimmed, const Dtk_bool inTrimLeadingCharacters=DTK_TRUE, const Dtk_bool inTrimTrailingCharacters=DTK_TRUE)
 Removes all occurrences of a given char at the beginning - leading - or the end - trailing - into the Dtk_string. More...
 
void TrimLeadingAndTrailingCharacters (const Dtk_WChar_t inCharToBeTrimmed)
 Removes all occurrences of a given char at the beginning - leading - and the end - trailing - into the Dtk_string. More...
 
void TrimLeadingCharacters (const Dtk_WChar_t inCharToBeTrimmed)
 Removes all occurrences of a given char at the beginning - leading - and the end - trailing - into the Dtk_string. More...
 
void TrimTrailingCharacters (const Dtk_WChar_t inCharToBeTrimmed)
 Removes all occurrences of a given char at the end - trailing - into the Dtk_string. More...
 
int unlink () const
 File Utility : Delete a file. More...
 
 ~Dtk_string ()
 Default destructors. More...
 

Static Public Member Functions

static const char PathSeparatorChar ()
 File Utility : retrieve The OS Path Separator as char. More...
 
static const Dtk_string PathSeparatorString ()
 File Utility : Retrieves The OS Path Separator as Dtk_string. More...
 
static const Dtk_WChar_t PathSeparatorWChar ()
 File Utility : Retrieves The OS Path Separator as Dtk_WChar_t. More...
 

Protected Member Functions

void _FillFromCharBuffer (const char *inBuffer, const Dtk_Size_t inSize=(Dtk_Size_t) -1)
 

Protected Attributes

char * m_CStr
 compatibility ASCII representation. WARNING this field is not always up to date. More...
 
Size_t m_CStrSize
 size of m_CStr buffer More...
 
Dtk_WChar_tm_Str
 Internal representation of the string. More...
 
Size_t m_StrSize
 size of m_Str buffer More...
 

Friends

bool operator!= (const Dtk_string &s1, const Dtk_string &s2)
 compare two Dtk_string More...
 
Dtk_string operator+ (const Dtk_string &s1, const Dtk_string &s2)
 concat two Dtk_string More...
 
bool operator< (const Dtk_string &s1, const Dtk_string &s2)
 compare two Dtk_string More...
 
std::ostream & operator<< (std::ostream &, const Dtk_string &)
 
bool operator<= (const Dtk_string &s1, const Dtk_string &s2)
 compare two Dtk_string More...
 
bool operator== (const Dtk_string &s1, const Dtk_string &s2)
 compare two Dtk_string More...
 
bool operator> (const Dtk_string &s1, const Dtk_string &s2)
 compare two Dtk_string More...
 
bool operator>= (const Dtk_string &s1, const Dtk_string &s2)
 compare two Dtk_string More...
 

Detailed Description

This is a high level string class.

This class lets you use ASCII or UNICODE strings. It also has some File fonctions

Member Typedef Documentation

◆ Size_t

typedef size_t Dtk_string::Size_t

Constructor & Destructor Documentation

◆ ~Dtk_string()

Dtk_string::~Dtk_string ( )

Default destructors.

◆ Dtk_string() [1/9]

Dtk_string::Dtk_string ( )

Default constructor.

◆ Dtk_string() [2/9]

Dtk_string::Dtk_string ( const char *  s)

constructor from a char * (ASCII string)

Parameters
sthe ASCII string to convert

◆ Dtk_string() [3/9]

Dtk_string::Dtk_string ( const char *  s,
const Dtk_Size_t inCount 
)

◆ Dtk_string() [4/9]

Dtk_string::Dtk_string ( const Dtk_string )

copy constructor

Parameters
sthe Dtk_string to copy

◆ Dtk_string() [5/9]

Dtk_string::Dtk_string ( Dtk_string &&  s)

Move constructor.

Parameters
sthe Dtk_string to move
97  {
98  s.m_Str = 0;
99  s.m_CStr = 0;
100  s.m_StrSize = 0;
101  s.m_CStrSize = 0;
102  }

◆ Dtk_string() [6/9]

Dtk_string::Dtk_string ( const double  dbl_val)

constructor from a double

Parameters
dbl_valthe double value to convert

◆ Dtk_string() [7/9]

Dtk_string::Dtk_string ( const double  dbl_val,
Dtk_Int32  inWithMorePrecision 
)

◆ Dtk_string() [8/9]

Dtk_string::Dtk_string ( const float  float_val)

constructor from a float

Parameters
float_valthe float value to convert

◆ Dtk_string() [9/9]

Dtk_string::Dtk_string ( const Dtk_WChar_t s)

Member Function Documentation

◆ _FillFromCharBuffer()

void Dtk_string::_FillFromCharBuffer ( const char *  inBuffer,
const Dtk_Size_t  inSize = (Dtk_Size_t) -1 
)
protected

◆ _w_str_us()

const Dtk_WChar_t* Dtk_string::_w_str_us ( ) const

Retrieve the UNICODE string.

Returns
the UNICODE string
Warning
You can't modify the returned string !!

Sample:

wchar_t * tmp_char;
tmp_char = res.w_str(); //you can't modify the tmp_char value

◆ add_int()

void Dtk_string::add_int ( const int  integer,
int  force_unsigned_int = 0 
)

concat an int to the Dtk_string (convert the int to Dtk_string)

Parameters
integerthe int to concat

Sample:

Dtk_string s1,res;
int val;
s1 = L"first string";
val = 2;
s1.add_int(val); //Now res is L"first string2"

◆ c_str()

const char* Dtk_string::c_str ( ) const

Retrieve the ASCII conversion string.

Returns
the ASCII string
Warning
You can't modify the returned string !!

Sample:

char * tmp_char;
tmp_char = res.c_str(); //you can't modify the tmp_char value

◆ cat()

void Dtk_string::cat ( const Dtk_string s2)

concat the Dtk_string with the Dtk_string given in parameter

Parameters
s2the Dtk_string to concat

Sample:

Dtk_string s1,s2;
s1 = L"first string";
s2 = L"second string";
s1.cat(s2); //Now s1 is L"first stringsecond string"
Remarks
this method is similar to operator '+'

◆ clear()

void Dtk_string::clear ( )

clear string data

Sample:

Dtk_string tmp = L"one_text";
tmp.clear(); //Now tmp is ""

◆ cmp() [1/2]

int Dtk_string::cmp ( const Dtk_string s2) const

compare the Dtk_string with the string given in parameter

Parameters
s2: Dtk_string to be compared with
Returns
> 0 if this is greater than s2, 0 if they are identical, < 0 else

Sample:

Dtk_string s1,s2;
...
if(s1.cmp(s2) != 0)
{
...
}
Remarks
this method is similar to '==', '<', '>', '>=', '<=', '!=' operators

◆ cmp() [2/2]

int Dtk_string::cmp ( const Dtk_WChar_t s2) const

◆ convert_from_int()

void Dtk_string::convert_from_int ( const int  integer,
int  force_unsigned_int = 0 
)

affectation operator from a int

Parameters
integerthe affected value (a conversion is made)

Sample:

tmp.convert_from_int(1); //Now tmp is "1"

◆ ConvertFromUTF8String()

void Dtk_string::ConvertFromUTF8String ( const char *  inUTF8String)

◆ count_char_occurrences()

int Dtk_string::count_char_occurrences ( const int  car) const

Counts all the occurrences of a given character into the Dtk_string.

Parameters
carthe searched substring
Returns
the occurrences number of the car.

Sample:

int nb;
s1 = L"occurrences";
nb = s1.count_char_occurrences('c'); //Now nb is equal to 3

◆ count_substring_occurrences()

int Dtk_string::count_substring_occurrences ( const Dtk_string substring) const

Counts all the occurrences of a given substring into the Dtk_string.

Parameters
substringthe searched substring
Returns
the occurrences number of the substring.

Sample:

int nb;
s1 = L"first string. Second string";
s2 = L"string";
nb = s1.count_substring_occurrences(s2); //Now nb is equal to 2

◆ cpy()

void Dtk_string::cpy ( Dtk_string  s2)

copy the Dtk_string given in parameter in the Dtk_string

Parameters
s2the Dtk_string to be copied

Sample:

Dtk_string s1,s2;
s1 = L"first string";
s2 = L"second string";
s1.cpy(s2); //Now s1 is L"second string"
Remarks
this method is similar to operator '='

◆ drive()

Dtk_string Dtk_string::drive ( ) const

File Utility : Retrieves the drive in Dtk_string form.

Returns
the drive string

Sample:

Dtk_string s1,res;
s1 = L"C:\\dir\\dir2\\filename.extension";
res = s1.drive(); //result is L"C:"

◆ existe_fichier()

Dtk_bool Dtk_string::existe_fichier ( ) const

File Utility : tests if a file exists.

Returns
true if file exists false else

Sample:

s1 = L"C:\\dir\\dir2\\filename.extension";
res = s1.existe_fichier();
if(res)
{
s1.unlink(); // We delete the file
}

◆ extension()

Dtk_string Dtk_string::extension ( ) const

File Utility : Retrieves the extension in Dtk_string form.

Returns
the extension string

Sample:

Dtk_string s1,res;
s1 = L"C:\\dir\\dir2\\filename.extension";
res = s1.extension(); //result is L"extension"

◆ filename()

Dtk_string Dtk_string::filename ( ) const

File Utility : Retrieves the filename in Dtk_string form.

Returns
the filename string

Sample:

Dtk_string s1,res;
s1 = L"C:\\dir\\dir2\\filename.extension";
res = s1.filename(); //result is L"filename"

◆ FileNameExtension()

void Dtk_string::FileNameExtension ( Dtk_string outFileNameExtension) const

File Utility : Retrieves the filename extension in Dtk_string form.

Returns
the filename extension string

Sample:

Dtk_string s1,res;
s1 = L"C:\\dir\\dir2\\filename.extension";
s1.FileNameExtension( res ); //res == L"filename.extension"

◆ FileSize()

Dtk_Size_t Dtk_string::FileSize ( ) const

File Utility : retrieve the file size.

Returns
The file size if success 0 else

Sample:

s1 = L"C:\\dir\\dir2\\filename.extension";
size = s1.FileSize();

◆ find_first()

int Dtk_string::find_first ( int  character) const

find the position of a character into a Dtk_string

Parameters
carthe searched character (UNICODE or ASCII form)
Returns
the position of the first occurrence of car if success -1 else

Sample:

int pos;
s1 = L"first string";
pos = s1.find_first(L's'); //Now pos is equal to 3

◆ find_last()

int Dtk_string::find_last ( int  character) const

find the position of a character into a Dtk_string

Parameters
carthe searched character (UNICODE or ASCII form)
Returns
the position of the last occurrence of car if success -1 else

Sample:

int pos;
s1 = L"first string";
pos = s1.find_last(L's'); //Now pos is equal to 6

◆ find_substring()

int Dtk_string::find_substring ( const Dtk_string s1) const

find the position of a substring into a Dtk_string

Parameters
s1the searched substring
Returns
the position of the first character of the substring if success -1 else

Sample:

Dtk_string s1,s2;
int pos;
s1 = L"first string";
s2 = L"str";
pos = s1.find_substring(s2); //Now pos is equal to 6

◆ FixPathSeparator()

void Dtk_string::FixPathSeparator ( )

File Utility : Fixes path separator consistency. It lets you replace the '\' or '/' by the OS needed separator.

Remarks
It uses the PathSeparatorChar method to get the correct path separator.

Sample:

s1 = L"\\dir/dir2\\filename.extension";
On Windows the path is now L"\\dir\\dir2\\filename.extension"
On Linux/MacOS the path is now L"/dir/dir2/filename.extension"

◆ free_mem()

void Dtk_string::free_mem ( )

◆ FullPath()

void Dtk_string::FullPath ( Dtk_string outFullPath) const

File Utility : Retrieves the full path in Dtk_string form.

Returns
the full path string

Sample:

Dtk_string s1,res;
s1 = L"C:\\dir\\dir2\\filename.extension";
s1.FullPath( res ); //res == L"C:/dir/dir2/"
Remarks
the full path '\' are converted into '/'.

◆ get_char()

Dtk_Size_t Dtk_string::get_char ( char *  inoutStr) const

copy the Dtk_string in a char * (ASCII) string

Parameters
inoutStrthe buffer string. If NULL the method only processes the resulting ASCII length - for buffer allocation -
Returns
The ASCII string length.

Sample:

char * tmp = NULL;
s1 = L"first string";
Dtk_Size_t Len = s1.get_char(tmp); //We process the resulting string length
tmp = new char[Len + 1];
s1.get_char(tmp); //Now tmp is "first string"
Warning
the str string must be allocated before the method call
Remarks
there is a conversion from UNICODE to ASCII string so some ugly characters may occur...

◆ get_wchar()

void Dtk_string::get_wchar ( Dtk_WChar_t str) const

copy the Dtk_string in a char * (UNICODE) string

Parameters
strthe buffer string

Sample:

wchar_t * tmp;
s1 = L"first string";
tmp = new wchar_t[s1.len() + 1];
s1.get_wchar(tmp); //Now tmp is L"first string"
Warning
the str string must be allocated before the method call

◆ icmp() [1/2]

int Dtk_string::icmp ( const Dtk_string s2) const

Perform a lowercase comparison of strings.

Parameters
s2: Dtk_string to be compared with
Returns
> 0 if this is greater than s2, 0 if they are identical, < 0 else

Sample:

Dtk_string s1,s2;
...
if(s1.cmp(s2,3) != 0)
{
...
}

◆ icmp() [2/2]

int Dtk_string::icmp ( const Dtk_WChar_t s2) const

◆ is_not_NULL()

Dtk_bool Dtk_string::is_not_NULL ( ) const

◆ is_NULL()

Dtk_bool Dtk_string::is_NULL ( ) const

◆ left()

Dtk_string Dtk_string::left ( int  pos) const

retrieve the left part of the Dtk_string from a position

Parameters
pos: start position
Returns
the left part of the Dtk_string if success or a NULL Dtk_string else

Sample:

Dtk_string s1,s2;
s1 = L"first string";
s2 = s1.left(3); //Now s2 is equal to L"firs"
Remarks
the pivot character is included in the resulted Dtk_string

◆ left_exclusive()

Dtk_string Dtk_string::left_exclusive ( int  pos) const

retrieve the left part of the Dtk_string from a position

Parameters
pos: start position
Returns
the left part of the Dtk_string if success or a NULL Dtk_string else

Sample:

Dtk_string s1,s2;
s1 = L"first string";
s2 = s1.left_exclusive(3); //Now s2 is equal to L"fir"
Remarks
the pivot character is NOT included in the resulted Dtk_string

◆ LeftExclusive()

void Dtk_string::LeftExclusive ( const int &  pos,
Dtk_string outRes 
) const

◆ len()

int Dtk_string::len ( ) const

Retrieve the length of the Dtk_string.

Returns
the Dtk_string length

Sample:

int length;
length = res.len();

◆ Merge()

void Dtk_string::Merge ( const Dtk_string s2)

◆ mkdir()

int Dtk_string::mkdir ( ) const

File Utility : Create a Directory.

Returns
0 if success -1 else

Sample:

FILE * res;
s1 = L"C:\\dir\\dir2\\";
res = s1.mkdir();

◆ ncmp() [1/2]

int Dtk_string::ncmp ( const Dtk_string s2,
const int  count 
) const

compare the count first character of the Dtk_string with the string given in parameter

Parameters
s2: Dtk_string to be compared with
count: the number of characters to be compared
Returns
> 0 if this is greater than s2, 0 if they are identical, < 0 else

Sample:

Dtk_string s1,s2;
...
if(s1.cmp(s2,3) != 0)
{
...
}

◆ ncmp() [2/2]

int Dtk_string::ncmp ( const Dtk_WChar_t s2,
const int  count 
) const

◆ ncpy()

void Dtk_string::ncpy ( const Dtk_string s2,
size_t  size 
)

copy a number of characters of the Dtk_string in an other Dtk_string

Parameters
s2the Dtk_string to be copied
sizethe number of character to be copied

Sample:

Dtk_string s1,s2;
s2 = L"first string";
s1.ncpy(s2,4); //Now s1 is L"firs"

◆ nicmp() [1/2]

int Dtk_string::nicmp ( const Dtk_string s2,
const size_t  size 
) const

Compare characters of two strings without regard to case.

Parameters
s2: Dtk_string to be compared with
size: the number of characters to be compared
Returns
> 0 if this is greater than s2, 0 if they are identical, < 0 else

Sample:

Dtk_string s1,s2;
...
if(s1.cmp(s2,3) != 0)
{
...
}

◆ nicmp() [2/2]

int Dtk_string::nicmp ( const Dtk_WChar_t s2,
const size_t  size 
) const

◆ OpenFile()

FILE* Dtk_string::OpenFile ( const Dtk_string inRights) const

File Utility : Open a file with the given rights.

Parameters
inRightsthe given rights (in ASCII, UNICODE or Dtk_string form
  • you can use define such as 'DTK_A' or 'DTK_WP' for example - )
Returns
the FILE * pointer if success or NULL else

Sample:

FILE * res;
s1 = L"C:\\dir\\dir2\\filename.extension";
res = s1.OpenFile(DTK_WP);
if(res)
fclose(res); // We close the file

◆ operator+=()

Dtk_string& Dtk_string::operator+= ( const Dtk_string s2)

◆ operator=() [1/5]

Dtk_string& Dtk_string::operator= ( const char *  s)

affectation operator from a char (ASCII) string

Parameters
sthe affected value

Sample:

tmp = "this is a sample"; //Now tmp is "this is a sample"

◆ operator=() [2/5]

Dtk_string& Dtk_string::operator= ( const double  dbl_val)

affectation operator from a double

Parameters
dbl_valthe affected value (a conversion is made)

Sample:

tmp = (double)1.0; //Now tmp is "1.0"

◆ operator=() [3/5]

Dtk_string& Dtk_string::operator= ( const Dtk_string s)

affectation operator from a Dtk_string

Parameters
sthe affected value

Sample:

Dtk_string res("this is a sample");
tmp = res; //Now tmp is "this is a sample"

◆ operator=() [4/5]

Dtk_string& Dtk_string::operator= ( const float  fltval)

affectation operator from a float

Parameters
fltvalthe affected value (a conversion is made)

Sample:

tmp = (float)1.0; //Now tmp is "1.0"

◆ operator=() [5/5]

Dtk_string& Dtk_string::operator= ( Dtk_string &&  s)

Move assignment operator.

Parameters
sthe Dtk_string to move
107  {
108  if( this != &s )
109  {
110  delete[] m_Str;
111  delete[] m_CStr;
112  m_Str = s.m_Str;
113  m_CStr = s.m_CStr;
114  m_StrSize = s.m_StrSize;
116 
117  s.m_Str = 0;
118  s.m_CStr = 0;
119  s.m_StrSize = 0;
120  s.m_CStrSize = 0;
121  }
122 
123  return *this;
124  }

◆ operator[]() [1/2]

const Dtk_WChar_t& Dtk_string::operator[] ( int  i) const

◆ operator[]() [2/2]

Dtk_WChar_t& Dtk_string::operator[] ( int  )

access to a specified letter in the Dtk_string

Parameters
ithe position of the wanted letter
Returns
the letter

◆ ouvrir_fichier()

FILE* Dtk_string::ouvrir_fichier ( const Dtk_string droits) const

File Utility : Open a file with the given rights.

Parameters
droitsthe given rights (in ASCII, UNICODE or Dtk_string form
  • you can use define such as 'DTK_A' or 'DTK_WP' for example - )
Returns
the FILE * pointer if success or NULL else

Sample:

FILE * res;
s1 = L"C:\\dir\\dir2\\filename.extension";
if(res)
fclose(res); // We close the file

◆ path()

Dtk_string Dtk_string::path ( ) const

File Utility : Retrieves the path in Dtk_string form.

Returns
the path string

Sample:

Dtk_string s1,res;
s1 = L"C:\\dir\\dir2\\filename.extension";
res = s1.path(); //result is L"\dir\dir2\"

◆ PathSeparatorChar()

static const char Dtk_string::PathSeparatorChar ( )
static

File Utility : retrieve The OS Path Separator as char.

Returns
'\' on Windows/Cygwin, '/' otherwise.
896  {
897 # if defined(_WIN32) || defined(__CYGWIN__) // Windows default, including MinGW and Cygwin
898  return '\\';
899 # else
900  return '/';
901 # endif
902  }

◆ PathSeparatorString()

static const Dtk_string Dtk_string::PathSeparatorString ( )
static

File Utility : Retrieves The OS Path Separator as Dtk_string.

Returns
"\\" on Windows/Cygwin, "/" otherwise.
916  {
917 # if defined(_WIN32) || defined(__CYGWIN__) // Windows default, including MinGW and Cygwin
918  return L"\\";
919 # else
920  return "/";
921 # endif
922  }

◆ PathSeparatorWChar()

static const Dtk_WChar_t Dtk_string::PathSeparatorWChar ( )
static

File Utility : Retrieves The OS Path Separator as Dtk_WChar_t.

Returns
L'\' on Windows/Cygwin, L'/' otherwise.
906  {
907 # if defined(_WIN32) || defined(__CYGWIN__) // Windows default, including MinGW and Cygwin
908  return L'\\';
909 # else
910  return L'/';
911 # endif
912  }

◆ RawCopyFromASCII()

void Dtk_string::RawCopyFromASCII ( const char *  inStrToBeCopied,
const Dtk_Size_t  inCount = -1 
)

◆ removechar()

int Dtk_string::removechar ( const int &  removed_char)

Removes all occurrences of a character in a string.

Parameters
removed_char: character to be removed

Sample:

s1 = L"first string";
s1.removechar(L'r'); // Now s1 is equal to L"fist sting"

◆ replace()

int Dtk_string::replace ( const int &  old_char,
const int &  new_char 
)

Replaces all occurrences of a character in a string with a new character.

Parameters
old_char: character to be replaced
new_char: character to replace

Sample:

s1 = L"first string";
s1.replace(L's', L't'); // Now s1 is equal to L"firtt ttring"

◆ right()

Dtk_string Dtk_string::right ( int  pos) const

retrieve the right part of the Dtk_string from a position

Parameters
pos: start position
Returns
the right part of the Dtk_string if success or a NULL Dtk_string else

Sample:

Dtk_string s1,s2;
s1 = L"first string";
s2 = s1.right(3); //Now s2 is equal to L"st string"
Remarks
the pivot character is included in the resulted Dtk_string

◆ right_exclusive()

Dtk_string Dtk_string::right_exclusive ( int  pos) const

retrieve the right part of the Dtk_string from a position

Parameters
pos: start position
Returns
the right part of the Dtk_string if success or a NULL Dtk_string else

Sample:

Dtk_string s1,s2;
s1 = L"first string";
s2 = s1.right_exclusive(3); //Now s2 is equal to L"t string"
Remarks
the pivot character is NOT included in the resulted Dtk_string

◆ RightExclusive()

void Dtk_string::RightExclusive ( const int &  pos,
Dtk_string outRes 
) const

◆ rmdir()

int Dtk_string::rmdir ( ) const

◆ SetAsDeprecated()

Dtk_string::SetAsDeprecated ( "2022.3"  ,
"Use FileSize() method instead"   
) const

◆ Split() [1/2]

void Dtk_string::Split ( const Dtk_string inDelimiters,
Dtk_tab< Dtk_string > &  outResults 
) const

Split a Dtk_string into an array of Dtk_string giving a char array.

Parameters
inDelimitersthe delimiters string. This string contains each characters used to split the string
outResultsthe result array

Sample:

Dtk_string StringToBeSplitted = L"String To Be-Splitted";
Dtk_string Delimiters = L" -";
StringToBeSplitted.Split( Delimiters, Result);
//Now Result contains 4 elements
//Result.at(0) is equal to L"String"
//Result.at(1) is equal to L"To"
//Result.at(2) is equal to L"Be"
//Result.at(3) is equal to L"Splitted"

◆ Split() [2/2]

void Dtk_string::Split ( Dtk_WChar_t inDelimiters,
Dtk_tab< Dtk_string > &  outResults 
) const

◆ Substring()

Dtk_string Dtk_string::Substring ( const Dtk_Size_t inStartIndex,
const Dtk_Size_t inLength 
) const

◆ test_extension()

int Dtk_string::test_extension ( const Dtk_string ext) const

◆ ToDtkDouble64()

Dtk_status Dtk_string::ToDtkDouble64 ( Dtk_Double64 outRes) const

◆ ToDtkInt32()

Dtk_status Dtk_string::ToDtkInt32 ( Dtk_Int32 outRes) const

◆ ToLower()

void Dtk_string::ToLower ( )

Converts the Dtk_string to Lower case.

Sample:

Dtk_string s1 = L"My String";
s1.ToLower();
//Now the s1 is L"my string"

◆ ToUpper()

void Dtk_string::ToUpper ( )

Converts the Dtk_string to Upper case.

Sample:

Dtk_string s1 = L"My String";
s1.ToUpper();
//Now the s1 is L"MY STRING"

◆ ToUTF8String()

char* Dtk_string::ToUTF8String ( ) const

Converts the Dtk_string to UTF8 string.

Returns
The UTF8 String allocated with 'new'. Please use 'delete []' to free it.

Sample:

Dtk_string tmp = L"30°"; //special ascii string.
char * UTF8Str = tmp.ToUTF8String(); //UTF8Str is ''
delete [] UTF8Str; UTF8Str = NULL;

◆ traite_nom_fichier()

int Dtk_string::traite_nom_fichier ( Dtk_string drive,
Dtk_string path,
Dtk_string filename,
Dtk_string extension 
) const

File Utility: Splits Fullpath into drive/path/filename/extension.

Parameters
[out]drivedrive buffer or NULL if not wanted...
[out]pathpath buffer or NULL if not wanted...
[out]filenamefilename buffer or NULL if not wanted...
[out]extensionextension buffer or NULL if not wanted...
Returns
always 1

Sample:

s1 = L"c:\\toto\\tata\\titi\\tutu.tete";
//drive = L"c:"
//path = L"\toto\tata\titi\"
//filename = L"tutu"
//ext = L"tete"
s1 = L"/toto/tata/titi/tutu.tete ";
//drive = L""
//path = L"/toto/tata/titi/"
//filename = L"tutu"
//ext = L"tete"
s1 = L"toto/tata/titi/tutu.tete";
//drive = L""
//path = L"toto/tata/titi/"
//filename = L"tutu"
//ext = L"tete"
s1 = L"../tata/titi/tutu.tete";
//drive = L""
//path = L"../tata/titi/"
//filename = L"tutu"
//ext = L"tete"
s1 = L"tutu";
//drive = L""
//path = L""
//filename = L"tutu"
//ext = L""
s1 = L"titi/.tutu";
//drive = L""
//path = L"titi/"
//filename = L""
//ext = L"tutu"
s1 = L".tutu.tete";
//drive = L""
//path = L""
//filename = L".tutu"
//ext = L"tete"

◆ TrimCharacters()

void Dtk_string::TrimCharacters ( const Dtk_WChar_t  inCharToBeTrimmed,
const Dtk_bool  inTrimLeadingCharacters = DTK_TRUE,
const Dtk_bool  inTrimTrailingCharacters = DTK_TRUE 
)

Removes all occurrences of a given char at the beginning - leading - or the end - trailing - into the Dtk_string.

Parameters
inCharToBeTrimmedthe searched Dtk_WChar_t
inTrimLeadingCharactersDTK_TRUE If you want to trim leading characters. DTK_FALSE otherwise. DTK_TRUE by default.
inTrimTrailingCharactersDTK_TRUE If you want to trim leading characters. DTK_FALSE otherwise. DTK_TRUE by default.

Sample:

s1 = L" Test Test Test ";
s1.TrimCharacters( ' ', DTK_TRUE, DTK_FALSE ); //Trim only leading ' ' characters
//Now the string equals L"Test Test Test "

◆ TrimLeadingAndTrailingCharacters()

void Dtk_string::TrimLeadingAndTrailingCharacters ( const Dtk_WChar_t  inCharToBeTrimmed)

Removes all occurrences of a given char at the beginning - leading - and the end - trailing - into the Dtk_string.

Parameters
inCharToBeTrimmedthe searched Dtk_WChar_t

Sample:

s1 = L" Test Test Test ";
//Now the string equals L"Test Test Test"
628  {
629  TrimCharacters( inCharToBeTrimmed, DTK_TRUE, DTK_TRUE );
630  }

◆ TrimLeadingCharacters()

void Dtk_string::TrimLeadingCharacters ( const Dtk_WChar_t  inCharToBeTrimmed)

Removes all occurrences of a given char at the beginning - leading - and the end - trailing - into the Dtk_string.

Parameters
inCharToBeTrimmedthe searched Dtk_WChar_t

Sample:

s1 = L" Test Test Test ";
//Now the string equals L"Test Test Test "
600  {
601  TrimCharacters( inCharToBeTrimmed, DTK_TRUE, DTK_FALSE );
602  }

◆ TrimTrailingCharacters()

void Dtk_string::TrimTrailingCharacters ( const Dtk_WChar_t  inCharToBeTrimmed)

Removes all occurrences of a given char at the end - trailing - into the Dtk_string.

Parameters
inCharToBeTrimmedthe searched Dtk_WChar_t

Sample:

s1 = L" Test Test Test ";
//Now the string equals L" Test Test Test"
614  {
615  TrimCharacters( inCharToBeTrimmed, DTK_FALSE, DTK_TRUE );
616  }

◆ unlink()

int Dtk_string::unlink ( ) const

File Utility : Delete a file.

Returns
0 if success -1 else

Sample:

FILE * res;
s1 = L"C:\\dir\\dir2\\filename.extension";
if(res)
{
fclose(res); // We close the file
s1.unlink(); // We delete the file
}

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const Dtk_string s1,
const Dtk_string s2 
)
friend

compare two Dtk_string

Parameters
s1the first Dtk_string to compare
s2the second Dtk_string to compare
Returns
true if s1 is different of s2 false else

Sample:

Dtk_string s1,s2;
...
if(s1 != s2)
{
...
}

◆ operator+

Dtk_string operator+ ( const Dtk_string s1,
const Dtk_string s2 
)
friend

concat two Dtk_string

Parameters
s1the first Dtk_string to concat
s2the second Dtk_string to concat
Returns
the resulting Dtk_string

Sample:

Dtk_string s1,s2,res;
s1 = L"first string";
s2 = L"second string";
res = s1 + s2; //Now res is L"first stringsecond string"

◆ operator<

bool operator< ( const Dtk_string s1,
const Dtk_string s2 
)
friend

compare two Dtk_string

Parameters
s1the first Dtk_string to compare
s2the second Dtk_string to compare
Returns
true if s1 is smaller than s2 false else

Sample:

Dtk_string s1,s2;
...
if(s1 < s2)
{
...
}

◆ operator<<

std::ostream& operator<< ( std::ostream &  ,
const Dtk_string  
)
friend

◆ operator<=

bool operator<= ( const Dtk_string s1,
const Dtk_string s2 
)
friend

compare two Dtk_string

Parameters
s1the first Dtk_string to compare
s2the second Dtk_string to compare
Returns
true if s1 is smaller or equal than s2 false else

Sample:

Dtk_string s1,s2;
...
if(s1 <= s2)
{
...
}

◆ operator==

bool operator== ( const Dtk_string s1,
const Dtk_string s2 
)
friend

compare two Dtk_string

Parameters
s1the first Dtk_string to compare
s2the second Dtk_string to compare
Returns
true if they are identical false else

Sample:

Dtk_string s1,s2;
...
if(s1 == s2)
{
...
}

◆ operator>

bool operator> ( const Dtk_string s1,
const Dtk_string s2 
)
friend

compare two Dtk_string

Parameters
s1the first Dtk_string to compare
s2the second Dtk_string to compare
Returns
true if s1 is greater than s2 false else

Sample:

Dtk_string s1,s2;
...
if(s1 > s2)
{
...
}

◆ operator>=

bool operator>= ( const Dtk_string s1,
const Dtk_string s2 
)
friend

compare two Dtk_string

Parameters
s1the first Dtk_string to compare
s2the second Dtk_string to compare
Returns
true if s1 is greater or equal than s2 false else

Sample:

Dtk_string s1,s2;
...
if(s1 >= s2)
{
...
}

Field Documentation

◆ m_CStr

char* Dtk_string::m_CStr
mutableprotected

compatibility ASCII representation. WARNING this field is not always up to date.

◆ m_CStrSize

Size_t Dtk_string::m_CStrSize
mutableprotected

size of m_CStr buffer

◆ m_Str

Dtk_WChar_t* Dtk_string::m_Str
protected

Internal representation of the string.

◆ m_StrSize

Size_t Dtk_string::m_StrSize
mutableprotected

size of m_Str buffer

Dtk_string::cmp
int cmp(const Dtk_WChar_t *s2) const
Dtk_string::TrimTrailingCharacters
void TrimTrailingCharacters(const Dtk_WChar_t inCharToBeTrimmed)
Removes all occurrences of a given char at the end - trailing - into the Dtk_string.
Definition: dtk_string.hpp:613
Dtk_string::TrimCharacters
void TrimCharacters(const Dtk_WChar_t inCharToBeTrimmed, const Dtk_bool inTrimLeadingCharacters=DTK_TRUE, const Dtk_bool inTrimTrailingCharacters=DTK_TRUE)
Removes all occurrences of a given char at the beginning - leading - or the end - trailing - into the...
Dtk_string::ouvrir_fichier
FILE * ouvrir_fichier(const Dtk_string &droits) const
File Utility : Open a file with the given rights.
Dtk_string::TrimLeadingAndTrailingCharacters
void TrimLeadingAndTrailingCharacters(const Dtk_WChar_t inCharToBeTrimmed)
Removes all occurrences of a given char at the beginning - leading - and the end - trailing - into th...
Definition: dtk_string.hpp:627
Dtk_string::count_substring_occurrences
int count_substring_occurrences(const Dtk_string &substring) const
Counts all the occurrences of a given substring into the Dtk_string.
DTK_TRUE
#define DTK_TRUE
Definition: define.h:727
Dtk_string::cat
void cat(const Dtk_string &s2)
concat the Dtk_string with the Dtk_string given in parameter
Dtk_string::count_char_occurrences
int count_char_occurrences(const int car) const
Counts all the occurrences of a given character into the Dtk_string.
Dtk_string::TrimLeadingCharacters
void TrimLeadingCharacters(const Dtk_WChar_t inCharToBeTrimmed)
Removes all occurrences of a given char at the beginning - leading - and the end - trailing - into th...
Definition: dtk_string.hpp:599
Dtk_string
This is a high level string class.
Definition: dtk_string.hpp:58
Dtk_Size_t
size_t Dtk_Size_t
Definition: define.h:712
Dtk_string::unlink
int unlink() const
File Utility : Delete a file.
Dtk_string::convert_from_int
void convert_from_int(const int integer, int force_unsigned_int=0)
affectation operator from a int
DTK_WP
#define DTK_WP
Definition: dtk_string.hpp:44
Dtk_string::path
Dtk_string path() const
File Utility : Retrieves the path in Dtk_string form.
Dtk_string::ncpy
void ncpy(const Dtk_string &s2, size_t size)
copy a number of characters of the Dtk_string in an other Dtk_string
DTK_FALSE
#define DTK_FALSE
Definition: define.h:728
Dtk_bool
char Dtk_bool
Definition: define.h:725
Dtk_string::OpenFile
FILE * OpenFile(const Dtk_string &inRights) const
File Utility : Open a file with the given rights.
Dtk_string::ToUpper
void ToUpper()
Converts the Dtk_string to Upper case.
Dtk_string::right
Dtk_string right(int pos) const
retrieve the right part of the Dtk_string from a position
Dtk_string::find_substring
int find_substring(const Dtk_string &s1) const
find the position of a substring into a Dtk_string
Dtk_string::Split
void Split(const Dtk_string &inDelimiters, Dtk_tab< Dtk_string > &outResults) const
Split a Dtk_string into an array of Dtk_string giving a char array.
Dtk_string::existe_fichier
Dtk_bool existe_fichier() const
File Utility : tests if a file exists.
Dtk_string::add_int
void add_int(const int integer, int force_unsigned_int=0)
concat an int to the Dtk_string (convert the int to Dtk_string)
Dtk_string::m_CStrSize
Size_t m_CStrSize
size of m_CStr buffer
Definition: dtk_string.hpp:71
Dtk_string::replace
int replace(const int &old_char, const int &new_char)
Replaces all occurrences of a character in a string with a new character.
Dtk_string::filename
Dtk_string filename() const
File Utility : Retrieves the filename in Dtk_string form.
Dtk_string::ToUTF8String
char * ToUTF8String() const
Converts the Dtk_string to UTF8 string.
Dtk_string::FullPath
void FullPath(Dtk_string &outFullPath) const
File Utility : Retrieves the full path in Dtk_string form.
Dtk_string::cpy
void cpy(Dtk_string s2)
copy the Dtk_string given in parameter in the Dtk_string
Dtk_string::get_char
Dtk_Size_t get_char(char *inoutStr) const
copy the Dtk_string in a char * (ASCII) string
Dtk_string::get_wchar
void get_wchar(Dtk_WChar_t *str) const
copy the Dtk_string in a char * (UNICODE) string
Dtk_string::traite_nom_fichier
int traite_nom_fichier(Dtk_string *drive, Dtk_string *path, Dtk_string *filename, Dtk_string *extension) const
File Utility: Splits Fullpath into drive/path/filename/extension.
Dtk_string::FileNameExtension
void FileNameExtension(Dtk_string &outFileNameExtension) const
File Utility : Retrieves the filename extension in Dtk_string form.
Dtk_string::left
Dtk_string left(int pos) const
retrieve the left part of the Dtk_string from a position
Dtk_string::c_str
const char * c_str() const
Retrieve the ASCII conversion string.
Dtk_string::FileSize
Dtk_Size_t FileSize() const
File Utility : retrieve the file size.
Dtk_string::extension
Dtk_string extension() const
File Utility : Retrieves the extension in Dtk_string form.
Dtk_string::find_first
int find_first(int character) const
find the position of a character into a Dtk_string
Dtk_string::mkdir
int mkdir() const
File Utility : Create a Directory.
Dtk_string::clear
void clear()
clear string data
Dtk_string::left_exclusive
Dtk_string left_exclusive(int pos) const
retrieve the left part of the Dtk_string from a position
Dtk_string::FixPathSeparator
void FixPathSeparator()
File Utility : Fixes path separator consistency. It lets you replace the '\' or '/' by the OS needed ...
Dtk_string::drive
Dtk_string drive() const
File Utility : Retrieves the drive in Dtk_string form.
Dtk_string::find_last
int find_last(int character) const
find the position of a character into a Dtk_string
Dtk_tab< Dtk_string >
Dtk_string::right_exclusive
Dtk_string right_exclusive(int pos) const
retrieve the right part of the Dtk_string from a position
Dtk_string::m_StrSize
Size_t m_StrSize
size of m_Str buffer
Definition: dtk_string.hpp:69
Dtk_string::len
int len() const
Retrieve the length of the Dtk_string.
Dtk_string::m_Str
Dtk_WChar_t * m_Str
Internal representation of the string.
Definition: dtk_string.hpp:63
Dtk_string::ToLower
void ToLower()
Converts the Dtk_string to Lower case.
Dtk_string::m_CStr
char * m_CStr
compatibility ASCII representation. WARNING this field is not always up to date.
Definition: dtk_string.hpp:65
Dtk_string::removechar
int removechar(const int &removed_char)
Removes all occurrences of a character in a string.