Advanced string handling (SDL script)
This topic applies to SDL script extensions for TDK. For more information, see Overview of SDL script extensions for TDK (SDL script).
SDL Script Extensions for TDK:
The definition (and some implementation) of the TItsStr class is available in the ItsStr.h header file, located under the Modeler installation directory at <installation directory>\ItsShadow\TdkSources\BiCommon
Reference for using the TItsStr class
Definition: class TItsStr. Aliases: TStr
TItsSr inherits from TItsShortStr for internal reasons. TItsShortStr shall never been used directly by the user.
Constructors and destructor:
TItsStr ()
Builds a new string object initially empty. An empty string appears externally like a C char pointer to a NUL character
TItsStr (const char* S)
Builds a new string and sets it to the string pointed by S – the string pointed by S is copied internally so the value pointed by S does not need to persist
TItsStr (const char* Start, const char* FirstAfterEnd)
Builds a new string and sets it to the value pointed by Start and FirstAfterEnd, that must point different characters of the same string. The value is set in such a way all the characters between the one pointed by Start (included) and the one pointed by FirstAfterEnd (excluded) are copied into the string internal buffer
TItsStr (const TItsStr& S)
Copy constructor
TItsStr (const TItsShortStr& S)
Copy constructor from base type, do not use
virtual ~TItsStr ()
Redefined assignment operator for character expressions, replaces the content of the string object with the string specified (same effect of Set (S))
void Set (const char* Start, const char* FirstAfterEnd)
Empties the string then sets it to the value pointed by Start and FirstAfterEnd, that must point different characters of the same string. The value is set in such a way all the characters between the one pointed by Start (included) and the one pointed by FirstAfterEnd (excluded) are copied into the string internal buffer
void Append (char C)
Appends C at the end of the string
void Append (const char* S);
Appends the string pointed by S at the end of the string object
virtual void AppendLen (const char* S, int SLen);
Appends the string pointed by S at the end of the string object. Instead of evaluating the length of the string pointed by S, trusts the SLen indication provided by the caller. It is more efficient but it may cause errors if such indication is not correct
void AppendIfMissing (const char* What)
Appends the specified string at the end of the string object contents if the contents do not terminate with the same string already
const TItsShortStr& operator += (const char S)
const TItsShortStr& operator += (const char* S)
Redefined += operators for appending a single character and a string, respectively
void Prepend (char C)
void Prepend (const char* S)
Prepend (insert at the beginning of the string) a single character and a string, respectively
void Indent (int In)
Indents the string adding “In” spaces at the beginning of each line (i.e. at the beginning of the whole string, and after each \n character, except the last \n if it is the last character of the string). When used with negative “In”, outdents the string. Outdenting does not preserve original indentation if a negative “In” value is specified such that the (absolute value of) “In” exceeds the count of leading spaces on each line in the string object
void Repeat (char C, int N)
Appends N times the character C
void Cut (int Where)
Truncates the string object contents at the specified position (0 = truncate to zero characters). Does nothing if Where is specified out of bounds
void HeadCut (int Num)
Deletes the first Num characters of the string contents. If Num is more than the length of the contents, deletes all characters and the string remains empty
void TailCut (int Num)
Deletes the last Num characters of the string contents. If Num is more than the length of the contents, deletes all characters and the string remains empty
bool CutIfPresent (const char* What)
If the contents end with the string specified by What, deletes What from the end of the string and returns true
bool HeadCutIfPresent (const char* What)
If the contents start with the string specified by What, deletes What from the beginning of the string and returns true
void LTrim (char TrimChar = ' ')
Deletes all the leading characters equal to the specified character
void RTrim (char TrimChar = ' ')
Deletes all the trailing characters equal to the specified character
void Trim (char TrimChar = ' ')
Deletes all the leading and trailing characters equal to the specified character
void SetSeparator (const char* S)
Sets the string pointed by S as the separator that will be appended before any Append, AppendLen operation. The separator will be appended to the string object only if the string object is not empty. Set an empty string to reset the separator to its default empty value
void UCase ()
void LCase ()
Change the case of all characters in the string to upper case and lower case, respectively
int StrCmp (const char* S) const
Bytewise compares the string contents against the supplied S value and returns -1, 0, 1 if the contents are lower, equal or greater with respect to S. Comparison is case sensitive
int operator != (const TItsStr& S) const
int operator == (const TItsStr& S) const
int operator <(const TItsStr& S) const
int operator >(const TItsStr& S) const
int operator >= (const TItsStr& S) const
int operator <= (const TItsStr& S) const
Redefined comparison operators for a string object second operand
int operator != (const char* S) const
int operator == (const char* S) const
int operator <(const char* S) const
int operator >(const char* S) const
int operator >= (const char* S) const
int operator <= (const char* S) const
Redefined comparison operators for a const char* second operand
const TItsStr& operator = (const TItsStr& S)
Redefined assignment operator
const char* Get () const
Returns the string object contents as a constant pointer. When the string object is empty, returns a pointer to the NUL character
operator const char* () const
Redefined cast operator to const char*, has the same effects of Get
const char& operator[] (int Where) const
Redefined [] operator, returns the character at the specified position
int Length () const
int L () const
Return the length of the string object contents (excludes any terminating NUL character)
char Last () const
Returns the last character of the string object contents (or NUL if empty)
virtual bool EndsWith (const char* What) const
Returns true if the string object contents ends with the specified string
virtual bool StartsWith (const char* What) const;
Returns true if the string object contents starts with the specified string
int Find (const char* Pattern) const
Finds the Pattern within the contents and returns the number of occurrences found
int Subst (const char* Pattern, const char* Substitution)
Replaces each occurrence of Pattern with Substitution and returns the number of substitutions made
bool TrashUpTo (const char* Pattern, bool LeavePatternThere = false)
Finds the first occurrence of Pattern in the contents. If found, deletes all the characters before Pattern and returns true. In addition, if LeavePatternThere is false, also deletes the pattern itself
bool TrashSince (const char* Pattern, bool LeavePatternThere = false)
Finds the last occurrence of Pattern in the contents. If found, deletes all the characters after Pattern and returns true. In addition, if LeavePatternThere is false, also deletes the pattern itself
TItsOStrStream O ()
Returns a stream object to append expressions at the end of the string object, e.g. MyString.O() << “I was born in “ << 1963;
* 
Not all the expression types specifiable after “<<”are currently supported.
string BreakAt (const char *Searchstring, const char *Source)
Looks for the first occurrence of Searchstring within Source. This is a case-sensitive search. If the Searchstring is found, then the function returns the prefix of Searchstring (the substring before Searchstring) and removes the Searchstring from Source. If Searchstring is not found within Source, the function returns the value of Source, emptying the Source string.
int Return(const char *Targetstring, const char *Pattern, const char *Replacementstring)
Replaces the Replacementstring in Targetstring and returns the number of replacements done (case sensitive).
void Error(const char *Errormessage, Object, List)
Formats and prints in the ACS log the specified Errormessage, focusing on the object, and supported by the optional context List - the context should be used whenever possible to specify additional objects to look up in order to properly understand the origin of the error.
void HeadCutCommonPrefix (char *Targetstring, const char *Prefixstring)
Cuts the prefix that is common between Target and Prefix (case sensitive). If found, the Prefixstring is removed from the Targetstring. Prefix remains unchanged. Used to shorten the full scoped name (Targetstring) of an object against the specific scope (Prefixstring) where it is used
int Contains(const char *Targetstring, const char *Searchstring)
Returns the number of occurrences of Searchstring within Targetstring (case sensitive).
string Isolate(const char *String, const char *Substring)
Finds the first occurrence of the Substring within String (case sensitive). The Substring is usually a single character or a few character separators.
If an occurrence is found, then the Substring from the beginning of String to the separator, which is excluded, is extracted and returned. The extracted substring (including the separator) is removed from the String.
If String does not contain Substring, then the whole String is returned, and then the String is left as an empty string
int Split (const char * Sourcestring, const char *Substring, const char *String1, const char *String2)
Searches for the first occurrence of Substring within Sourcestring, (case sensitive). The Substring is usually a single character or a few character separators.
If an occurrence is found, String is set as a substring from the beginning of Sourcestring to the separator, which is excluded, and String2 is set to the substring from the separator, which is excluded, to the end of the Sourcestring, and a nonzero value is returned.
If the Sourcestring does not contain Substring, String1 is set to the whole Sourcestring, String2 is set to an empty string, and a zero is returned.