C12Adapter Opensource C++ Interface
MStr Class Reference

Provides static methods for string manipulation. More...

Inheritance diagram for MStr:

Public Types

enum  Masks {
  StrNone = 0x00,
  StrXML = 0x01,
  StrInternational = 0x02,
  StrQuote = 0x04,
  StrKeepSideBlanks = 0x08,
  StrNoBackslashEscape = 0x10,
  StrShortEscapes = 0x20
}
 Enumeration type that defines string transformation. More...
 
enum  WordWrappingConstants {
  MinimumLineWidth = 20,
  DefaultLineWidth = 100
}
 Constants used in word wrapping algorithm. More...
 

Static Public Member Functions

static MStdString Decode (const MStdString &encoding, const MByteString &str, const MStdString &badChar=MVariant::s_emptyString)
 Decode a byte string in a specific encoding into a UTF-8 string. More...
 
static MWideString Decode (const MStdString &encoding, const MByteString &str, const MWideString &badChar)
 Decode a byte string in a specific encoding into a Unicode string. More...
 
static MStdStringVector GetAllSupportedEncodings ()
 Return all encodings supported. More...
 
static MStdString ToString (const MStdString &str, unsigned mask)
 
static MWideString ToString (const MWideString &str, unsigned mask)
 
static MStdString FromString (const MStdString &str, unsigned mask)
 
static MWideString FromString (const MWideString &str, unsigned mask)
 
static MStdString ToXMLString (const MStdString &str)
 
static MWideString ToXMLString (const MWideString &str)
 
static MStdString FromXMLString (const MStdString &str)
 
static MWideString FromXMLString (const MWideString &str)
 
static char EscapeToChar (const char *str, const char **strEnd=NULL)
 
static wchar_t EscapeToChar (const wchar_t *str, const wchar_t **strEnd=NULL)
 
static char XMLEscapeToChar (const char *str, const char **strEnd=NULL)
 
static wchar_t XMLEscapeToChar (const wchar_t *str, const wchar_t **strEnd=NULL)
 
static MStdString ToQuotedEscapedString (const MStdString &str)
 
static MWideString ToQuotedEscapedString (const MWideString &str)
 
static MStdString ToEscapedString (const MStdString &str)
 
static MWideString ToEscapedString (const MWideString &str)
 
static MStdString ToEscapedXmlString (const MStdString &str)
 
static MWideString ToEscapedXmlString (const MWideString &str)
 
static MStdString CharToEscapedString (char ch)
 
static MWideString CharToEscapedString (wchar_t ch)
 
static MStdString CharToQuotedEscapedString (char ch)
 
static MWideString CharToQuotedEscapedString (wchar_t ch)
 
static MStdString FromEscapedString (const MStdString &str)
 
static MWideString FromEscapedString (const MWideString &str)
 
static MStdString ToUpper (const MStdString &par)
 
static char ToUpper (char par)
 
static MWideString ToUpper (const MWideString &par)
 
static wchar_t ToUpper (wchar_t par)
 
static MStdString ToLower (const MStdString &par)
 
static char ToLower (char par)
 
static MWideString ToLower (const MWideString &par)
 
static wchar_t ToLower (wchar_t par)
 
static MStdString WordWrap (const MStdString &str, unsigned indentCount=0, unsigned lineWidth=DefaultLineWidth)
 
static MWideString WordWrap (const MWideString &str, unsigned indentCount=0, unsigned lineWidth=DefaultLineWidth)
 
static int Compare (const MStdString &s1, const MStdString &s2, bool ignoreCase=false)
 
static int Compare (const MWideString &s1, const MWideString &s2, bool ignoreCase=false)
 
static MByteString Encode (const MStdString &encoding, const MStdString &str, const MByteString &badChar=MVariant::s_emptyString)
 
static MByteString Encode (const MStdString &encoding, const MWideString &str, const MByteString &badChar)
 
- Static Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 Get the declared class of this particular object. More...
 
static bool IsClassPresent (const MStdString &name)
 Tells if the given class name is available. More...
 

Additional Inherited Members

- Public Member Functions inherited from MObject
virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () const =0
 Get the final class of the object. More...
 
virtual unsigned GetEmbeddedSizeof () const
 For embedded object types, return the size of the class. More...
 
bool IsEmbeddedObject () const
 Tell if the object is of embedded kind. More...
 
SHOW_INTERNAL MVariant Call (const MStdString &name, const MVariant &params)
 Call the object service with parameters, given as variant. More...
 
MVariant Call0 (const MStdString &name)
 Call the object service with no parameters. More...
 
MVariant Call1 (const MStdString &name, const MVariant &p1)
 Call the object service with one parameter. More...
 
MVariant Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2)
 Call the object service with two parameter. More...
 
MVariant Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3)
 Call the object service with three parameter. More...
 
MVariant Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4)
 Call the object service with four parameter. More...
 
MVariant Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5)
 Call the object service with five parameter. More...
 
MVariant Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6)
 Call the object service with six parameter. More...
 
virtual MVariant CallV (const MStdString &name, const MVariant::VariantVector &params)
 Call the object service with parameters, given as variant vector. More...
 
virtual bool IsPropertyPresent (const MStdString &name) const
 Tell if the property with the given name exists.
 
virtual bool IsServicePresent (const MStdString &name) const
 Tell if the service with the given name exists.
 
virtual MVariant GetProperty (const MStdString &name) const
 Get the property value using name of the property. More...
 
virtual void SetProperty (const MStdString &name, const MVariant &value)
 Set the property using name of the property, and value. More...
 
virtual MStdStringVector GetAllPropertyNames () const
 Return the list of publicly available properties, persistent or not. More...
 
virtual MStdStringVector GetAllPersistentPropertyNames () const
 Return the list of persistent properties. More...
 
virtual void SetPersistentPropertiesToDefault ()
 Set the persistent properties of the object to their default values. More...
 
virtual MVariant GetPersistentPropertyDefaultValue (const MStdString &name) const
 Get the default value of persistent property with the name given. More...
 
virtual void SetPersistentPropertyToDefault (const MStdString &name)
 Set the persistent property with the name given to default value. More...
 
virtual const char * GetType () const
 Get the name of the type for the object (could be the same as class name).
 
virtual void SetType (const MStdString &)
 Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More...
 
virtual void Validate ()
 Validate internal structures of the object. More...
 
- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 
- Protected Member Functions inherited from MObject
 MObject ()
 Object constructor, protected as the class is abstract.
 
void DoSetPersistentPropertiesToDefault (const MClass *staticClass)
 Set the persistent properties to their default values for one object provided the class for that object. More...
 

Detailed Description

Provides static methods for string manipulation.

Member Enumeration Documentation

Enumeration type that defines string transformation.

Enumerator
StrNone 

No extra string processing, only C string escapes (backslashes)

StrXML 

Handle string for XML or HTML storage.

StrInternational 

Allow non-ASCII characters in string.

StrQuote 

Expect or produce quotes around string.

StrKeepSideBlanks 

Whether to keep blank characters at the sides, or change them into '\x20'.

StrNoBackslashEscape 

For StrXML only, instead of backslashes use XML escapes where possible.

StrShortEscapes 

Instead of numerics such as '\x0A' use standard C escapes '\n', '\r', and so on.

Constants used in word wrapping algorithm.

Enumerator
MinimumLineWidth 

Minimum line width for word wrapping. A word 20 characters wide is "internationalization".

DefaultLineWidth 

Default line width for word wrapping.

Member Function Documentation

static MStdString MStr::CharToEscapedString ( char  ch)
static

Convert any character to a printable string, possibly a C-like escape character.

If the character is a blank, it is represented as "\\x20".

Parameters
chCharacter to represent.
Returns
Result string.
static MWideString MStr::CharToEscapedString ( wchar_t  ch)
static

Convert any character to a printable string, possibly a C-like escape character.

If the character is a blank, it is represented as "\\x20".

Parameters
chCharacter to represent.
Returns
Result string.
static MStdString MStr::CharToQuotedEscapedString ( char  ch)
static

Convert any character to a quoted printable string, possibly a C-like escape character.

If the character is a blank, it is represented as "'\\x20'". Apostrophe is used for quoting a character.

Parameters
chCharacter to represent.
Returns
Result quoted string.
static MWideString MStr::CharToQuotedEscapedString ( wchar_t  ch)
static

Convert any character to a quoted printable string, possibly a C-like escape character.

If the character is a blank, it is represented as "'\\x20'". Apostrophe is used for quoting a character.

Parameters
chCharacter to represent.
Returns
Result quoted string.
static int MStr::Compare ( const MStdString s1,
const MStdString s2,
bool  ignoreCase = false 
)
static

Compare two given strings.

Parameters
s1First string to compare.
s2Second string to compare.
ignoreCaseWhen true, ignore the character case, default value is false.
Returns
Zero if strings are equal, positive if the first string is bigger, negative is the second is bigger.
static int MStr::Compare ( const MWideString s1,
const MWideString s2,
bool  ignoreCase = false 
)
static

Compare two given strings.

Parameters
s1First string to compare.
s2Second string to compare.
ignoreCaseWhen true, ignore the character case, default value is false.
Returns
Zero if strings are equal, positive if the first string is bigger, negative is the second is bigger.
static MStdString MStr::Decode ( const MStdString encoding,
const MByteString str,
const MStdString badChar = MVariant::s_emptyString 
)
static

Decode a byte string in a specific encoding into a UTF-8 string.

The list of all encodings supported by the library is available in GetAllSupportedEncodings property. Currently, only one-byte encodings are supported plus UTF-8. When UTF-8 is specified the method does nothing.

Parameters
encodingEncoding of the given byte string, see encodingNames for supported names.
strByte string in an encoding given as first parameter.
badCharWhich character to use in case the character cannot be represented. If it is an empty string an error will be thrown if a character that cannot be represented is seen.
Returns
UTF-8 string.
static MWideString MStr::Decode ( const MStdString encoding,
const MByteString str,
const MWideString badChar 
)
static

Decode a byte string in a specific encoding into a Unicode string.

The list of all encodings supported by the library is available in GetAllSupportedEncodings property. Currently, only one-byte encodings are supported plus UTF-8. When UTF-8 is specified the method does nothing.

Parameters
encodingEncoding of the given byte string, see encodingNames for supported names.
strByte string in an encoding given as first parameter.
badCharWhich character to use in case the character cannot be represented. If it is an empty string an error will be thrown if a character that cannot be represented is seen.
Returns
Unicode wide string, UTF-16 on Windows, or UTF-32 on Posix compatible OS such as Linux.
static MByteString MStr::Encode ( const MStdString encoding,
const MStdString str,
const MByteString badChar = MVariant::s_emptyString 
)
static

Encode a string to a byte string that represents a specific encoding.

Parameters
encodingDesired encoding of the result byte string, see encodingNames for supported names.
strString in UTF-8.
badCharWhich character to use in case the character cannot be represented. If it is an empty string an error will be thrown if a character that cannot be represented is seen.
Returns
Byte string in a desired encoding.
static MByteString MStr::Encode ( const MStdString encoding,
const MWideString str,
const MByteString badChar 
)
static

Encode a string to a byte string that represents a specific encoding.

Parameters
encodingDesired encoding of the result byte string, see encodingNames for supported names.
strString in UTF-8.
badCharWhich character to use in case the character cannot be represented. If it is an empty string an error will be thrown if a character that cannot be represented is seen.
Returns
Byte string in a desired encoding.
static char MStr::EscapeToChar ( const char *  str,
const char **  strEnd = NULL 
)
static

Convert the string that can contain a C-style string escape sequence into a character.

Parameters
strPointer to string, text that contains a C escape.
strEndOutput, result pointer to the end of C escape.
Returns
Result binary character.
Precondition
The first parameter is not NULL, otherwise the behavior is undefined.
See also
FromEscapedString
ToEscapedString
static wchar_t MStr::EscapeToChar ( const wchar_t *  str,
const wchar_t **  strEnd = NULL 
)
static

Convert the string that can contain a C-style string escape sequence into a character.

Parameters
strPointer to string, text that contains a C escape.
strEndOutput, result pointer to the end of C escape.
Returns
Result binary character.
Precondition
The first parameter is not NULL, otherwise the behavior is undefined.
See also
FromEscapedString
ToEscapedString
static MStdString MStr::FromEscapedString ( const MStdString str)
static

Convert the text string with possible C-like escapes to binary string.

Parameters
strString with possible C escapes.
Returns
Result binary string.
See also
ToEscapedString
static MWideString MStr::FromEscapedString ( const MWideString str)
static

Convert the text string with possible C-like escapes to binary string.

Parameters
strString with possible C escapes.
Returns
Result binary string.
See also
ToEscapedString
static MStdString MStr::FromString ( const MStdString str,
unsigned  mask 
)
static

General FromString method that takes a mask that specifies what exactly needs to be done to a string.

Converts a general purpose escaped string back to value string.

Parameters
strText string with escapes to convert into binary form using mask transformations.
maskMask conversion flags, such as StrNone or StrXML.
Returns
Result binary string.
See also
ToString for reverse conversion.
static MWideString MStr::FromString ( const MWideString str,
unsigned  mask 
)
static

General FromString method that takes a mask that specifies what exactly needs to be done to a string.

Converts a general purpose escaped string back to value string.

Parameters
strText string with escapes to convert into binary form using mask transformations.
maskMask conversion flags, such as StrNone or StrXML.
Returns
Result binary string.
See also
ToString for reverse conversion.
static MStdString MStr::FromXMLString ( const MStdString str)
static

Convert the XML string with C escapes back into binary.

Parameters
strText string with possible C and XML escapes to convert into binary.
Returns
Result binary string, prepared for XML output.
See also
ToXMLString for reverse conversion.
static MWideString MStr::FromXMLString ( const MWideString str)
static

Convert the XML string with C escapes back into binary.

Parameters
strText string with possible C and XML escapes to convert into binary.
Returns
Result binary string, prepared for XML output.
See also
ToXMLString for reverse conversion.
static MStdStringVector MStr::GetAllSupportedEncodings ( )
static

Return all encodings supported.

Names consist of case insensitive English letters, digits and dash ('-'). The names returned by this method are always uppercase:

  • "8859-1" ISO/IEC 8859-1 Western European: German, Icelandic, Irish, Italian, Norwegian, Portuguese, Spanish
  • "8859-2" ISO/IEC 8859-2 Central European: Bosnian, Polish, Croatian, Czech, Slovak, Slovene, Serbian, Hungarian
  • "8859-3" ISO/IEC 8859-3 South European: Maltese, Esperanto
  • "8859-4" ISO/IEC 8859-4 North European: Estonian, Latvian, Lithuanian, Greenlandic, and Sami
  • "8859-5" ISO/IEC 8859-5 Latin/Cyrillic: Belarusian, Bulgarian, Macedonian, Russian, Serbian, Ukrainian
  • "8859-6" ISO/IEC 8859-6 Latin/Arabic
  • "8859-7" ISO/IEC 8859-7 Latin/Greek
  • "8859-8" ISO/IEC 8859-8 Latin/Hebrew
  • "8859-9" ISO/IEC 8859-9 Latin-5 Turkish
  • "8859-10" ISO/IEC 8859-10 Latin-6 Nordic: better fit for some North European languages than 8859-4
  • "8859-11" ISO/IEC 8859-11 Latin/Thai
  • "8859-13" ISO/IEC 8859-13 Latin-7 Baltic Rim: other variation of 8859-4 and 8859-10
  • "8859-14" ISO/IEC 8859-14 Latin-8 Celtic
  • "8859-15" ISO/IEC 8859-15 Latin-9 Better 8859-1 with the Euro sign
  • "8859-16" ISO/IEC 8859-16 Latin-10 South-Eastern European
  • "ACP" Windows only, active system 8-bit code page. There is no such encoding in the other operating systems
  • "ASCII" Standard 7-bit codepage
  • "CP1250" Microsoft ANSI/OEM Eastern Europe
  • "CP1251" Microsoft ANSI/OEM Cyrillic
  • "CP1252" Microsoft ANSI/OEM Latin I
  • "CP1253" Microsoft ANSI/OEM Greek
  • "CP1254" Microsoft ANSI/OEM Turkish
  • "CP1255" Microsoft ANSI/OEM Hebrew
  • "CP1256" Microsoft ANSI/OEM Arabic
  • "CP1257" Microsoft ANSI/OEM Baltic
  • "CP437" Microsoft DOS Latin US
  • "CP737" Microsoft DOS Greek
  • "CP775" Microsoft DOS Baltic Rim
  • "CP850" Microsoft DOS Latin1
  • "CP852" Microsoft DOS Latin2
  • "CP855" Microsoft DOS Cyrillic
  • "CP857" Microsoft DOS Turkish
  • "CP860" Microsoft DOS Portuguese
  • "CP861" Microsoft DOS Icelandic
  • "CP862" Microsoft DOS Hebrew
  • "CP863" Microsoft DOS French Canada
  • "CP864" Microsoft DOS Arabic
  • "CP865" Microsoft DOS Nordic
  • "CP866" Microsoft DOS Cyrillic Russian
  • "CP869" Microsoft DOS Greek2
  • "CP874" Microsoft DOS Thai
  • "UTF-8" UNICODE byte encoding
Returns
String array of supported encodings.
static MStdString MStr::ToEscapedString ( const MStdString str)
static

Converts the string that can contain any character to a string with possible C-like escapes.

The starting and trailing blanks are substituted to their escape sequences, so they can be seen by the interfaces which do not have them exposed in quotes. The blanks which are surrounded by the other characters are presented as just blanks.

Parameters
strBinary string to represent as a text.
Returns
The result text string.
See also
ToQuotedEscapedString
FromEscapedString
static MWideString MStr::ToEscapedString ( const MWideString str)
static

Converts the string that can contain any character to a string with possible C-like escapes.

The starting and trailing blanks are substituted to their escape sequences, so they can be seen by the interfaces which do not have them exposed in quotes. The blanks which are surrounded by the other characters are presented as just blanks.

Parameters
strBinary string to represent as a text.
Returns
The result text string.
See also
ToQuotedEscapedString
FromEscapedString
static MStdString MStr::ToEscapedXmlString ( const MStdString str)
static

Acts as ToEscapedString function, plus converts XML service symbols to escape sequences.

Parameters
strBinary string to represent as a text.
Returns
The result text string, with possible C and XML escapes.
See also
ToEscapedString
static MWideString MStr::ToEscapedXmlString ( const MWideString str)
static

Acts as ToEscapedString function, plus converts XML service symbols to escape sequences.

Parameters
strBinary string to represent as a text.
Returns
The result text string, with possible C and XML escapes.
See also
ToEscapedString
static MStdString MStr::ToLower ( const MStdString par)
static

Converts the given string to lower case depending on current system locale.

Parameters
parString or character to convert.
Returns
Lowercased string or character.
static char MStr::ToLower ( char  par)
static

Converts the given string to lower case depending on current system locale.

Parameters
parString or character to convert.
Returns
Lowercased string or character.
static MWideString MStr::ToLower ( const MWideString par)
static

Converts the given string to lower case depending on current system locale.

Parameters
parString or character to convert.
Returns
Lowercased string or character.
static wchar_t MStr::ToLower ( wchar_t  par)
static

Converts the given string to lower case depending on current system locale.

Parameters
parString or character to convert.
Returns
Lowercased string or character.
static MStdString MStr::ToQuotedEscapedString ( const MStdString str)
static

Acts as ToEscapedString function, plus it puts the result string into quotes.

Parameters
strBinary string to represent as a quoted text.
Returns
The result text string enclosed into quotes.
See also
ToEscapedString
static MWideString MStr::ToQuotedEscapedString ( const MWideString str)
static

Acts as ToEscapedString function, plus it puts the result string into quotes.

Parameters
strBinary string to represent as a quoted text.
Returns
The result text string enclosed into quotes.
See also
ToEscapedString
static MStdString MStr::ToString ( const MStdString str,
unsigned  mask 
)
static

General ToString method that takes a mask that specifies what exactly needs to be done to a string.

C-like escapes are used for nonprintables in any case. Converts the standard string that can contain any character to a string that is printable, and possibly containing C-like escape characters in places of non-printable characters.

Parameters
strBinary string to convert from using mask transformations.
maskMask conversion flags, such as StrNone or StrXML.
Returns
Result escaped string, text.
See also
FromString for reverse conversion.
static MWideString MStr::ToString ( const MWideString str,
unsigned  mask 
)
static

General ToString method that takes a mask that specifies what exactly needs to be done to a string.

C-like escapes are used for nonprintables in any case. Converts the standard string that can contain any character to a string that is printable, and possibly containing C-like escape characters in places of non-printable characters.

Parameters
strBinary string to convert from using mask transformations.
maskMask conversion flags, such as StrNone or StrXML.
Returns
Result escaped string, text.
See also
FromString for reverse conversion.
static MStdString MStr::ToUpper ( const MStdString par)
static

Converts the given string to upper case depending on current system locale.

Parameters
parString or character to convert.
Returns
Uppercased strings.
static char MStr::ToUpper ( char  par)
static

Converts the given string to upper case depending on current system locale.

Parameters
parString or character to convert.
Returns
Uppercased strings.
static MWideString MStr::ToUpper ( const MWideString par)
static

Converts the given string to upper case depending on current system locale.

Parameters
parString or character to convert.
Returns
Uppercased strings.
static wchar_t MStr::ToUpper ( wchar_t  par)
static

Converts the given string to upper case depending on current system locale.

Parameters
parString or character to convert.
Returns
Uppercased strings.
static MStdString MStr::ToXMLString ( const MStdString str)
static

Translate the contents of the string to C escaped string for XML representation.

This converts '<', '>', '&' and '"' to appropriate XML escape sequences.

Parameters
strBinary string with escapes to convert into binary.
Returns
Result binary string, prepared for XML output.
See also
FromXMLString for reverse conversion.
static MWideString MStr::ToXMLString ( const MWideString str)
static

Translate the contents of the string to C escaped string for XML representation.

This converts '<', '>', '&' and '"' to appropriate XML escape sequences.

Parameters
strBinary string with escapes to convert into binary.
Returns
Result binary string, prepared for XML output.
See also
FromXMLString for reverse conversion.
static MStdString MStr::WordWrap ( const MStdString str,
unsigned  indentCount = 0,
unsigned  lineWidth = DefaultLineWidth 
)
static

Make a multiline word wrapped representation of a given string.

Parameters
strString, which has to be word wrapped.
indentCountHow many blanks to use for indentation of the whole string when word wrapping.
lineWidthLine width around which the text has to be wrapped, default is 100.
Returns
The wrapped string.
static MWideString MStr::WordWrap ( const MWideString str,
unsigned  indentCount = 0,
unsigned  lineWidth = DefaultLineWidth 
)
static

Make a multiline word wrapped representation of a given string.

Parameters
strString, which has to be word wrapped.
indentCountHow many blanks to use for indentation of the whole string when word wrapping.
lineWidthLine width around which the text has to be wrapped, default is 100.
Returns
The wrapped string.
static char MStr::XMLEscapeToChar ( const char *  str,
const char **  strEnd = NULL 
)
static

Convert the string that can contains a XML-style string escape sequence into a character.

Parameters
strPointer to string, text that contains an XML escape.
strEndOutput, result pointer to the end of XML escape.
Returns
Result binary character.
Precondition
The first parameter is not NULL, otherwise the behavior is undefined.
static wchar_t MStr::XMLEscapeToChar ( const wchar_t *  str,
const wchar_t **  strEnd = NULL 
)
static

Convert the string that can contains a XML-style string escape sequence into a character.

Parameters
strPointer to string, text that contains an XML escape.
strEndOutput, result pointer to the end of XML escape.
Returns
Result binary character.
Precondition
The first parameter is not NULL, otherwise the behavior is undefined.