SDK:TXString: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
 
(74 intermediate revisions by the same user not shown)
Line 5: Line 5:
== What is this? ==
== What is this? ==


TXString is one of the SDK generic types. It is used to represent a string in VectorWorks plug-in communications.
TXString is one of the SDK generic types. It is used to represent a string in Vectorworks. TXString is Unicode-compliant since Vectorworks 2018.


Currently TXString is <b>NOT</b> Unicode.
== TXChar ==
TXString uses UTF-16 encoding since this encoding is natively used on Windows and Mac. There is a new typedef called <b>TXChar</b>, which is wchar_t on Windows and UniChar on Mac. Thus, TXChar uses UTF-16 encoding on both platforms.


== Comments about encoding issues ==
TXString uses std::basic_string<TXChar> internally to store Unicode characters. There are two new macros for creating Unicode character or string literal. The following are two examples.


VectorWorks generally stores strings in a Mac encoding.  The most common is MacRoman, which is used
<code lang="cpp">
for most European languages (English, German, French, etc.).
TXString txStr1 = txuc('&#x1F60A;');            // Unicode character
TXString txStr2 = txu("1文本2テキ3ßÜü4");  // Unicode string literal
</code>


If a system is set to Japanese, then it will use MacJapanese.
== Conversion to and from OS Native String Types ==
 
Using OS dependent components (e.g. types, functions, classes, etc.) should be avoided. If the code has the need to handle OS native string types, the following are examples to achieve that.
 
=== Windows ===
<code lang="cpp">
// You can use the following code if MFC is used.
// CString → TXString
TXString txStr = cStr;


Other common Mac encodings are MacKorean, MacChineseTrad, MacChineseSimp, MacGreek, MacHebrew and MacArabic.
// TXString → CString
CString cStr = txStr.GetData();
</code>


While the MacRoman encoding is used by the Macintosh OS, the Windows OS has its own equivalent, which
=== Mac ===
our code commonly refers to as Ansi (two important methods in TXString are <b>MacToAnsi</b> and <b>AnsiToMac</b>).
<code lang="cpp">
// CFString
// CFStringRef → TXString
TXString txStr = cfStr;


A single byte character has 256 possible values, and the lowest 128 possible values (0x00 to 0x7F) are the same in MacRoman and the Windows equivalent encodings.
// TXString → CFStringRef
CFStringRef cfStr = txStr.GetCFStringRef()
if(cfStr)
{
    ... // Do something with cfStr;
    CFRelease(cfStr);
}


The lowercase and uppercase letters in the English alphabet, numbers, and most punctuation symbols are in the lowest 128 values, so they are represented the same in  the MacRoman and equivalent Windows encodings.
// NSString
// NSString → TXString
TXString txStr = [nsStr toTXString];


However, many characters we would consider special are commonly  used in German, French and other European languages, and they are in the highest 128 values.
// TXString → NSString
NSString* nsStr = [NSString stringWithTXString:txStr];
</code>


Some examples are an 'é' with an accent mark or a 'ü' with umlauts.
== Precomposed and Decomposed Forms ==


If our code does not properly handle the encoding for strings with special characters, the user will see them displayed improperly.
Some Unicode characters can be represented in two forms, which are decomposed form and precomposed form (precomposed form is also called composite form or composed form). For example, ' パ ' can be represented by one Unicode character (U+30D1, precomposed form) or by two Unicode characters (U+30CF('ハ') + U+309A('°'), decomposed form). Internally, Vectorworks uses Unicode characters in precomposed form. Client code using VW SDK doesn't need to worry about the difference.


Generally VectorWorks keeps strings in the Mac encoding.
Developers need to pay attention to the difference when calling some native Mac functions. In most cases, characters from OS APIs (Mac or Windows) are in the precomposed form. There are some exceptions on Mac. Two of them are APIs handling URLs and plist files. When TXString objects are initiated from objects returned by OS in these areas, ToPrecomposed() can be called to convert decomposed form to precomposed form. If the code needs to return a string in decomposed form, ToDecomposed() can be called to do the conversion before sending it to the OS. For example, SDK file/folder classes convert decomposed strings from Mac APIs to precomposed form right after these calls. Thus, all strings processed and manipulated internally are in precomposed form, and the client code using VW SDK doesn't need to worry about this. (If strings are in different forms, string comparison won't work. In addition, methods like element access operator[] and GetLength() may return different results if strings are in decomposed form.)


When strings are read in from Macintosh resources, they are kept in the Mac encoding (this may not be true for strings from DITL resources, which are usually just displayed in a dialog, but these are only used in a few older dialogs).
== Surrogate Pairs ==


Strings stored in a VW document are all in the Mac encoding. If a user is running on Windows and enters a string in a dialog, when our code first gets the string it will be in the Ansi encoding, and our code will convert it to the Mac encoding.
Most Unicode characters can be represented by one UTF-16 character. However, Unicode characters greater than U+FFFF need two UTF-16 characters, called surrogate pairs. For example, Unicode character 'SMILING FACE WITH SMILING EYES' ( &#x1F60A;, U+1F60A) is represented by 0xD83D and 0xDE0A in UTF-16. Thus, it is possible to have a TXString with invalid UTF-16 characters at the edges after some manipulations, such as Truncate(...). TXString automatically removes invalid UTF-16 characters at the edges during the call to Mid(...), Left(...), Right(...), or Truncate(...). The client code can also call TrimLeftInvalidCharacter(), TrimRightInvalidCharacter(), or TrimInvalidCharacters() manually to remove invalid UTF-16 characters at the edges.


If a string is displayed in a dialog and the user is running in Windows, the string will be converted from Mac format to Ansi format before it is passed to the OS to display it.  The layout manager system takes care for all of this, and its interface uses the Mac format.
== Definition ==


A layout manager function for setting static text passes the text in Mac format. A layout manager function for getting the text from an edit box will return the text in the Mac format.
TXString class is defined in "GSString.X.h".


However VectorWorks filing code does not keep strings in the Mac encoding, but uses the native encoding (Mac when running on the Mac and Ansi when running on Windows).
=== Constructors and Destructors ===


The interface for the [[VCOM:VectorWorks:Filing:IFileIdentifier|IFileIdentifier]] and [[VCOM:VectorWorks:Filing:IFolderIdentifier|IFolderIdentifier]] classes uses the native encoding.  If code sets a [[VCOM:VectorWorks:Filing:IFileIdentifier|IFileIdentifier]], passing it a path, and it is running on Windows, the path needs to be passed in Ansi format. If code gets a path from a [[VCOM:VectorWorks:Filing:IFileIdentifier|IFileIdentifier]], and it is running on Windows, the path will be returned in Ansi format.
<code lang="cpp">
    TXString();                    // Default constructor
    TXString(const TXString& src); // Copy constructor
    TXString(TXString&& src);      // Move constructor
    TXString(const StdUStr& src);  // Copy constructor from StdUStr
    TXString(StdUStr&& src);        // Move constructor from StdUStr


The interface for VectorScript uses the Mac encoding.  Any string passed to a VS command should be in Mac
    // From other string type
encoding, and any strings received from a VS command are in Mac encoding.
    TXString(const std::string& src, ETXEncoding e = ETXEncoding::eUTF8);
    TXString(const std::wstring& src);
#if GS_MAC
    TXString(const CFStringRef& src);  // Construct from CFStringRef&
#endif


Whenever a string needs to be converted from Mac to Ansi format, it is best to use the TXString method <b>TXString::MacToAnsi</b>, and to convert from Ansi to Mac, use <b>TXString::AnsiToMac</b>.  These methods do nothing when called on the Mac.
    // Specify initial size
    explicit TXString(size_t nInitialSize);  // Specify size (size_t version)
    explicit TXString(int nInitialSize);    // Specify size (int version)


If called when on a double-byte system (Japanese, Chinese, Korean), these methods only do something for a few non-standard Japanese characters.  The shift-JIS Japanese encoding is identical on Mac and Windows except for a few characters.
    // From a buffer
    TXString(const char* src, ETXEncoding e = ETXEncoding::eUTF8);
    TXString(const char* src, size_t len, ETXEncoding e = ETXEncoding::eUTF8);


Either that is true of the Korean and Chinese encoding, or any strings in those languages will not display properly if moved to another platform.
    TXString(const unsigned char* src, ETXEncoding e = ETXEncoding::eUTF8);


If the system is set to Greek, we use special tables for converting between MacGreek and Windows Greek encodings.
    TXString(const UCChar* src);
    TXString(const UCChar* src, size_t len);


If the system is set to any other single-byte language, we use tables for converting between MacRoman and the Windows equivalent.
    TXString(const wchar_t* src);
    TXString(const wchar_t* src, size_t len);
   
    // From a character
    explicit TXString(char ch, size_t count = 1);
    explicit TXString(unsigned char ch, size_t count = 1);
    explicit TXString(UCChar ch, size_t count = 1);
    explicit TXString(wchar_t ch, size_t count = 1);
   
    // Destructor
    virtual ~TXString();
</code>


This means our MacToAnsi and AnsiToMac code does not support other single-byte scripts.
=== Assignment Operators ===


For example, if a user enters classnames in the Russian script, the classnames will not display properly if the VectorWorks document is moved to the opposite platform.
<code lang="cpp">
    TXString& operator=(const TXString& src);      // Copy assignment operator
    TXString& operator=(TXString&& src);            // Move assignment operator
    TXString& operator=(const std::string& src);    // Assignment from std::string
    TXString& operator=(const std::wstring&src);    // Assignment from std::wstring
#if GS_MAC
    TXString& operator=(const CFStringRef& src);    // Assignment from CFStringRef&
#endif
   
    // From a buffer
    TXString& operator=(const char *src);
    TXString& operator=(const unsigned char* src);
    TXString& operator=(const UCChar* src);
    TXString& operator=(const wchar_t* src);
   
    // From single character
    TXString& operator=(char ch);
    TXString& operator=(unsigned char ch);
    TXString& operator=(UCChar ch);
    TXString& operator=(wchar_t ch);
    TXString& operator=(int codePoint);        // For example: txString = 0x27
</code>


== Definition ==
=== Length Related Functions ===


<code lang="cpp">
<code lang="cpp">
class GS_COMP_API TXString : public TDebugObject
    size_t GetLength() const;
{
    size_t GetByteSize() const;
public:
    size_t GetEncodingLength(ETXEncoding e) const;
TXString();
   
explicit TXString(size_t nInitialSize);
    bool IsEmpty() const;
TXString(const TXString &src);
   
TXString(const char *src);
    TXString& SetLength(size_t len);
TXString(const char *src, size_t len);
    TXString& SetLength(size_t len, TXChar ch);
TXString(ConstGSStringPtr src);
    TXString& Truncate(size_t len);
TXString(char ch, size_t cnt);
    TXString& Clear();
TXString(short strListID, short index);
</code>


template <size_t maxCharLen>
=== Element Access ===
TXString(const PStr<maxCharLen>& src);


virtual ~TXString();
<code lang="cpp">
    TXChar& operator[](ptrdiff_t nIndex);
    TXChar operator[](ptrdiff_t nIndex) const;
    TXChar& GetAt(size_t nIndex);
    TXChar GetAt(size_t nIndex) const;
    TXChar& GetLast();
    TXChar GetLast() const;
    TXString& SetAt(size_t nIndex, TXChar ch);
</code>


// overloaded assignment
=== Concatenation ===
TXString& operator=(const TXString& src);
TXString& operator=(const char *src);
TXString& operator=(ConstGSStringPtr src);
TXString& operator=(char ch);
template <size_t maxCharLen>
TXString& operator=(const PStr<maxCharLen>& src);


size_t GetLength() const;
<code lang="cpp">
unsigned char GetPascalLength() const;
    // Extends string from another TXString object
bool SetLength(size_t len);
    TXString& operator+=(const TXString& src);
bool SetLength(size_t len, char fill);
   
void Truncate(size_t len);
    // Extends string from character buffer
bool IsEmpty() const;
    TXString& operator+=(const char* src);           // UTF-8
void Empty(bool bQuick=false);
    TXString& operator+=(const unsigned char* src);  // UTF-8
void Clear();
    TXString& operator+=(const UCChar* src);
// Free any extra memory being used to hold string data.
    TXString& operator+=(const wchar_t* src);
void FreeExtra();
   
    // Extends string by one character
    TXString& operator+=(char ch);
    TXString& operator+=(unsigned char ch);
    TXString& operator+=(UCChar ch);
    TXString& operator+=(wchar_t ch);
    TXString& operator+=(int n);  // Unicode code point, for example: 0x63
   
    // String concatenation by using '<<'
    TXString& operator<<(const TXString& src);
   
    // Extends string from character buffer
    TXString& operator<<(const char *src);           // UTF-8
    TXString& operator<<(const unsigned char* src);   // UTF-8
    TXString& operator<<(const UCChar* src);
    TXString& operator<<(const wchar_t* src);
   
    // Extends string by one character
    TXString& operator<<(char ch);
    TXString& operator<<(unsigned char ch);
    TXString& operator<<(UCChar ch);
    TXString& operator<<(wchar_t ch);
   
    // Append a number as string
    TXString& operator<<(Sint32 number);
    TXString& operator<<(Sint64 number);
    TXString& operator<<(Uint32 number);
    TXString& operator<<(Uint64 number);
    TXString& operator<<(double number);
#if GS_MAC
    TXString& operator<<(size_t number);    // size_t is different from Uint64 on the mac
#endif
    TXString& operator<<(const GSHandle h);  // as number
</code>


void CopyInto(GSCStrPtr sz) const;
=== Insertion and Deletion ===
void CopyInto(GSStringPtr ps) const;


char GetAt(size_t nIndex) const;
<code lang="cpp">
char operator[](int nIndex) const;
    // Insert another TXString at position 'pos'.
char& operator[](int nIndex);
    TXString& Insert(size_t pos, const TXString& src);
void SetAt(size_t nIndex, char ch);
   
    // Insert one buffer at position 'pos'.
    TXString& Insert(size_t pos, const char* src);
    TXString& Insert(size_t pos, const unsigned char* src);  // UTF-8
    TXString& Insert(size_t pos, const UCChar* src);
    TXString& Insert(size_t pos, const wchar_t* src);
   
    // Insert one character 'ch' at position 'pos'.
    TXString& Insert(size_t pos, char ch);
    TXString& Insert(size_t pos, unsigned char ch);
    TXString& Insert(size_t pos, UCChar ch);
    TXString& Insert(size_t pos, wchar_t ch);
    TXString& Insert(size_t pos, int ch);                   // e.g. 0xA5, '¥'
   
    // Delete characters starting from 'pos' for 'len' characters.
    TXString& Delete(size_t pos, size_t len = (size_t) -1);
   
    // Delete the last character
    TXString& DeleteLast();
   
    // Trims white spaces (' ', '\t') or invalid chars
    TXString& TrimLeft();
    TXString& TrimRight();
    TXString& Trim();


operator const char*() const;
    TXString& TrimLeftInvalidCharacter();
operator const unsigned char*() const;
    TXString& TrimRightInvalidCharacter();
    TXString& TrimInvalidCharacters();
// Use these two functions to pass a TXString as a non-const string parameter.
</code>
// *** NOTE: You MUST call ReleaseUnsafePtr afterwards to reset the TXString length fields
char* GetUnsafeCharPtr(size_t len);
unsigned char* GetUnsafeUnsignedCharPtr(size_t len) ;
void ReleaseUnsafePtr();


// This function is older, but we didn't want to change the whole project right away.
=== Replacement, Conversion, Reversion ===
void ReleaseUnsafeCharPtr();
// string concatenation
const TXString& operator+=(const TXString& string);
const TXString& operator+=(char ch);
const TXString& operator+=(const char *sz);
const TXString& operator+=(const unsigned char *ps);


template <size_t maxCharLen>
<code lang="cpp">
const TXString& operator+=(const PStr<maxCharLen>& string);
    // Replaces all 'oldStr' with 'newSTr'.
    TXString& Replace(const TXString& oldStr, const TXString& newStr, bool bIgnoreCase = false);
TXString& operator<<(const TXString& str);
   
TXString& operator<<(char ch);
    // Upper case and lower case conversion
TXString& operator<<(const char *sz);
    TXString& MakeUpper();
TXString& operator<<(const unsigned char *ps);
    TXString& MakeLower();
TXString& operator<<(long n);
   
    // Reverse the string.
    TXString& MakeReverse();
   
    // Conversion to a Unicode normalization form
    TXString& ToPrecomposed();
    TXString& ToDecomposed();
</code>


template <size_t maxCharLen>
=== Getting Data and Casting ===
TXString& operator<<(const PStr<maxCharLen>& str);


// string comparison
<code lang="cpp">
int Compare(const TXString &str) const;
    // Returns const pointer to the TXChar buffer.
int Compare(const char *sz) const;
    const TXChar* GetData() const;
int Compare(const unsigned char *pstr) const;
    const TXChar* GetTXCharPtr() const;
template <size_t maxCharLen>
   
int Compare(const PStr<maxCharLen> &str) const;
    // Casting operators
    operator const char*() const;          // UTF-8
    operator const unsigned char*() const; // UTF-8
    operator const UCChar*() const;        // Unsigned short, UTF-16
    operator const wchar_t*() const;        // wchar_t: Win:UTF-16, Mac:UTF-32
   
    // Casting operators in function form.
    const char* GetCharPtr() const { return (operator const char*()); }
    const unsigned char* GetUCharPtr() const { return (operator const unsigned char*()); }
    const UCChar* GetUCCharPtr() const { return (operator const UCChar*()); }
    const wchar_t* GetWCharPtr() const { return (operator const wchar_t*()); }
   
    // Returns a std string or wstring
    std::string GetStdString(ETXEncoding e = ETXEncoding::eUTF8) const;
    std::wstring GetStdWString() const;
#if GS_MAC
    CFStringRef GetCFStringRef() const;
#endif
</code>


int CompareNoCase(const TXString &str) const;
=== Copying Data into External Buffer ===
int CompareNoCase(const char *sz) const;
int CompareNoCase(const unsigned char *pstr) const;
template <size_t maxCharLen>
int CompareNoCase(const PStr<maxCharLen> &str) const;


// simple sub-string extraction
<code lang="cpp">
TXString Mid(size_t nFirst, size_t nCount) const;
    // Note: 'bufSize' is the size of the buffer in bytes. For example, "xyz" needs four
TXString Mid(size_t nFirst) const;
    // bytes to include '\0' at the end.
TXString Left(size_t nCount) const;
TXString Right(size_t nCount) const;


TXString SpanIncluding(const TXString &str) const;
    void CopyInto(char* dst,
TXString SpanIncluding(const char *sz) const;
                  size_t bufSize,
TXString SpanIncluding(const unsigned char *ps) const;
                  ETXEncoding e = ETXEncoding::eUTF8) const;
TXString SpanExcluding(const TXString &str) const;
TXString SpanExcluding(const char *sz) const;
TXString SpanExcluding(const unsigned char *ps) const;


// Deleting and Inserting
    void CopyInto(unsigned char* ps,
void Delete(size_t pos, size_t len);
                  size_t bufSize,
void Insert(size_t pos, const char *sz);
                  ETXEncoding e = ETXEncoding::eUTF8) const;
void Insert(size_t pos, const unsigned char *ps);
   
void Insert(size_t pos, char ch, size_t cnt = 1);
    void CopyInto(UCChar* dst, size_t bufElemSize) const;
void Replace(const char *oldStr, const char *newStr, bool bIgnoreCase = false);
void Replace(const char *oldStr, char newChar, bool bIgnoreCase = false);


// upper/lower/reverse conversion
    void CopyInto(wchar_t* dst, size_t bufElemSize) const;
void MakeUpper();
</code>
void MakeLower();
void MakeReverse();


// Trimming whitespace (either side).
=== Searching Functions ===
void Trim();
void TrimLeft();
void TrimRight();


// Searching from left to right.  Return starting index, or -1 if not found.
<code lang="cpp">
int Find(char ch, int nStart = 0) const;
    ptrdiff_t Find(const TXString &subStr, size_t posFirst = 0, bool bIgnoreCase = false) const;
int FindNoSJISCheck(char ch, int nStart = 0) const;
    ptrdiff_t Find(int ch, size_t posFirst = 0, bool bIgnoreCase = false) const;
int FindOneOf(const TXString &charSet) const;
    ptrdiff_t Find(char ch, size_t posFirst = 0, bool bIgnoreCase = false) const;
int FindOneOf(const char *szCharSet) const;
   
int FindOneOf(const unsigned char *psCharSet) const;
    ptrdiff_t ReverseFind(const TXString &subStr, size_t posLast = -1, bool bIgnoreCase = false) const;
int FindNotOneOf(const TXString &charSet) const;
    ptrdiff_t ReverseFind(int ch, size_t posLast = -1, bool bIgnoreCase = false) const;
int FindNotOneOf(const char *szCharSet) const;
    ptrdiff_t ReverseFind(char ch, size_t posLast = -1, bool bIgnoreCase = false) const;
int FindNotOneOf(const unsigned char *psCharSet) const;
   
    ptrdiff_t FindOneOf(const TXString &charSet, size_t posFirst = 0) const;
    ptrdiff_t ReverseFindOneOf(const TXString &charSet, size_t posLast = -1) const;
   
    ptrdiff_t FindNotOneOf(const TXString &charSet, size_t posFirst = 0) const;
    ptrdiff_t ReverseFindNotOneOf(const TXString &charSet, size_t posLast = -1) const;
</code>


// Searching from right to left.  Return starting index, or -1 if not found.
=== Surrogate Functions ===
int ReverseFind(char ch, bool checkForJISChar = true) const;
int ReverseFindOneOf(const TXString &charSet) const;
int ReverseFindOneOf(const char *szCharSet) const;
int ReverseFindOneOf(const unsigned char *pstrCharSet) const;
int ReverseFindNotOneOf(const TXString &charSet) const;
int ReverseFindNotOneOf(const char *szCharSet) const;
int ReverseFindNotOneOf(const unsigned char *pstrCharSet) const;


// Look for a specific sub-string.
<code lang="cpp">
int Find(const TXString &sub, bool bIgnoreCase = false) const;
    bool SurrogatePairAt(size_t nIndex) const;
int Find(const char *szSub, bool bIgnoreCase = false) const;
    bool HasSurrogatePair() const;
int Find(const unsigned char *psSub, bool bIgnoreCase = false) const;
</code>
int Find(size_t nFirst, const TXString &sub, bool bIgnoreCase = false) const;
int Find(size_t nFirst, const char *szSub, bool bIgnoreCase = false) const;
int Find(size_t nFirst, const unsigned char *psSub, bool bIgnoreCase = false) const;


bool Load(short strListID, short index, EEmptyHandling allowEmpty = eDontAllowEmptyResult);
=== Creating Substring ===


// simple formatting
<code lang="cpp">
// passing a class reference before a variable-length argument list doesn't work in windows
    TXString Mid(size_t nFirst, size_t len = -1) const;
void Format(const char *szFormat, ...);
    TXString Left(size_t len) const;
void Format(const unsigned char *psFormat, ...);
    TXString Right(size_t len) const;
void Format(short strList, short index, ...);
</code>
void VFormat(const char *szFormat, va_list marker);
void itoa(int value);
int atoi() const;
Real64 atof() const;
operator int() const;
operator Real64() const;


short AnsiToMac();
=== Conversion to and from Numerics ===
short MacToAnsi();


/**
<code lang="cpp">
@brief Converts windows new line characters to mac new line characters
    Sint32 atoi() const;
    Sint64 atoi64() const;
The Mac has only a single line feed character (10) as a new line while
    Real64 atof() const;
Windows has a carriage return (13) followed by a line feed (10). This
    TXString& itoa(Sint64 value);
function removes any line feed characters in the string.
    TXString& ftoa(Real64 value);
*/
    TXString& ftoa(Real64 value, Sint32 precision);
void WinToMacNewLine ();
    static TXString ToStringInt(Sint64 value);
    static TXString ToStringInt(Sint64 value, Sint32 width, wchar_t paddingChar);
    static TXString ToStringReal(Real64 value);
    static TXString ToStringReal(Real64 value, Sint32 precision, bool fixed=true);
    template<typename T>
    static TXString ToString(T value);
    template<typename T>
    static TXString ToStringHex(T value, bool upperCase = true, size_t symbolsCnt = size_t(-1));
</code>
 
=== Checking TXChar Types ===
 
<code lang="cpp">
    static bool IsPunctuation(TXChar aTXChar);
    static bool IsWhitespace(TXChar aTXChar);
</code>
 
=== Comparison Methods ===


/**
<code lang="cpp">
@brief Converts mac new line characters to windows new line characters
    // Equality functions
    bool Equal(const TXString &str) const;
Prepends a carriage return (13) to an existing line feed character (10)
    bool EqualNoCase(const TXString &str) const;
if one does not already exist.
   
*/
    // Comparison functions
void MacToWinNewLine ();
    Sint32 Compare(const TXString &str) const;
};
    Sint32 CompareNoCase(const TXString &str) const;
</code>
</code>


== Function ==
=== Formating ===
 
<code>TXString::Format</code> and <code>static TXString::Formatted</code> can be used to generate formatted strings. These functions require known types to be used:
*short, unsigned short
*int, unsigned int
*long, unsigned long
*long long, unsigned long long
*double
*const char
*const char* -- a UTF-8 encoded string
*const wchar_t
*const wchar_t* -- this type depends on the OS, UTF-16 on Windows and UTF-32 on Mac.
*const void* -- a generic pointer
*TXString
 
They support the % markers: d, i, u, o, x, X, f, F, e, E, g, G, a, A, c, s, p, n
 
=== Related Non-member Functions ===
 
<code lang="cpp">
// Comparison operators
bool operator==(const TXString& lhs, const TXString& rhs);
bool operator==(const TXString& lhs, const char* rhs);
bool operator==(const char* lhs, const TXString& rhs);
bool operator==(const TXString& lhs, const TXChar* rhs);
bool operator==(const TXChar* lhs, const TXString& rhs);
 
bool operator!=(const TXString& lhs, const TXString& rhs);
bool operator!=(const TXString& lhs, const char* rhs);
bool operator!=(const char* lhs, const TXString& rhs);
bool operator!=(const TXString& lhs, const TXChar* rhs);
bool operator!=(const TXChar* lhs, const TXString& rhs);
 
bool operator<=(const TXString& lhs, const TXString& rhs);
bool operator>=(const TXString& lhs, const TXString& rhs);


<to be supplied>
bool operator<(const TXString& lhs, const TXString& rhs);
bool operator>(const TXString& lhs, const TXString& rhs);
 
// Plus operator
TXString operator+(const TXString& lhs, const TXString& rhs);
TXString operator+(const TXString& lhs, TXChar rhs);
TXString operator+(TXChar lhs, const TXString& rhs);
TXString operator+(const TXString& lhs, const TXChar* rhs);
TXString operator+(const TXChar* lhs, const TXString& rhs);
 
// Non-member swap function
void swap(TXString& lhs, TXString& rhs);
</code>


== Iterators ==
== Iterators ==
Line 311: Line 487:
TXString* operator->() const;
TXString* operator->() const;
};
};
</code>
== Displaying String Content in Xcode Debug Area ==
TXString uses a C++ STL container to store string content. Xcode displays the container information in a way that is difficult to read the string content. Since LLDB debugger provides the entire API as Python functions ([https://lldb.llvm.org/varformats.html LLDB Data Formatters]), we can use this feature to display string content in a clear format. In this example, two files are created in the user folder (/users/yourname/). One is ".lldbinit" and the other is "lldb_vectorworks.py".
.lldbinit
<code lang="Python">
command script import ~/lldb_vectorworks.py
</code>
lldb_vectorworks.py
<code lang="Python">
#=========================================================================================
# lldb_vectorworks.py
# The following code is for displaying TXString content in Xcode debug area.
#=========================================================================================
import sys
import lldb
import lldb.formatters.Logger
CATEGORY_NAME = "vectorworks"
#=========================================================================================
# For displaying StdUStr summary in Xcode
def StdUStrSummary(valobj,internal_dict):
middle = valobj.GetChildAtIndex(0).GetChildAtIndex(0).GetChildAtIndex(0).GetChildAtIndex(0)
__s = middle.GetChildAtIndex(1)
modeAndSize = __s.GetChildAtIndex(0).GetChildAtIndex(0).GetValueAsUnsigned(0)
# String to be returned later.
retStr = u'u"'
if (modeAndSize & 1) == 0:  # Short/static form
size = (modeAndSize >> 1)
# Current max array size is 11. If size is greater than 11, this object is not
# initialized and the content should be empty.
if size < 12:
txCharBuf = __s.GetChildAtIndex(1).GetPointeeData(0, size).uint16
for i in range(size):
if txCharBuf[i] == 0:
break;
retStr = retStr + unichr(txCharBuf[i])
else:  # Long/dynamic form
__l = middle.GetChildAtIndex(0)
# We only show the first 1000 characters.
size = __l.GetChildAtIndex(1).GetValueAsUnsigned(0)
if size > 1000:
size = 1000
txCharBuf = __l.GetChildAtIndex(2).GetPointeeData(0, size).uint16
for i in range(size):
if txCharBuf[i] == 0:
break;
retStr = retStr + unichr(txCharBuf[i])
retStr = retStr + u'"'
return retStr.encode('utf-8')
#=========================================================================================
# For displaying TXString summary in Xcode
def TXStringSummary(valobj,internal_dict):
return StdUStrSummary(valobj.GetChildMemberWithName('stdUStr'), internal_dict)
#=========================================================================================
def __lldb_init_module(debugger, dict):
reload(sys)
sys.setdefaultencoding('utf-8')
# StdUStr and TXString
debugger.HandleCommand('type summary add -F lldb_vectorworks.StdUStrSummary StdUStr --category %s' % CATEGORY_NAME)
debugger.HandleCommand('type summary add -F lldb_vectorworks.TXStringSummary TXString --category %s' % CATEGORY_NAME)
# Enable the vectorworks category
debugger.HandleCommand("type category enable %s" % CATEGORY_NAME)
#=========================================================================================
</code>
</code>


Line 316: Line 576:


[[Category:SDK Types|TXString]]
[[Category:SDK Types|TXString]]
[[SDK:Vectorworks 2018 Unicode]]

Latest revision as of 18:42, 13 June 2018

.SDK|SDK ..SDK:Types|SDK Types ..VCOM:VCOM (Vectorworks Component Object Model)|VCOM Basics ..VCOM:Class Reference|VCOM Class Reference

What is this?

TXString is one of the SDK generic types. It is used to represent a string in Vectorworks. TXString is Unicode-compliant since Vectorworks 2018.

TXChar

TXString uses UTF-16 encoding since this encoding is natively used on Windows and Mac. There is a new typedef called TXChar, which is wchar_t on Windows and UniChar on Mac. Thus, TXChar uses UTF-16 encoding on both platforms.

TXString uses std::basic_string<TXChar> internally to store Unicode characters. There are two new macros for creating Unicode character or string literal. The following are two examples.

TXString txStr1 = txuc('😊');             // Unicode character
TXString txStr2 = txu("1文本2テキ3ßÜü4");  // Unicode string literal

Conversion to and from OS Native String Types

Using OS dependent components (e.g. types, functions, classes, etc.) should be avoided. If the code has the need to handle OS native string types, the following are examples to achieve that.

Windows

// You can use the following code if MFC is used.
// CString → TXString
TXString txStr = cStr;

// TXString → CString
CString cStr = txStr.GetData();

Mac

// CFString
// CFStringRef → TXString
TXString txStr = cfStr;

// TXString → CFStringRef
CFStringRef cfStr = txStr.GetCFStringRef()
if(cfStr)
{
    ... // Do something with cfStr;
    CFRelease(cfStr);
}

// NSString
// NSString → TXString
TXString txStr = [nsStr toTXString];

// TXString → NSString
NSString* nsStr = [NSString stringWithTXString:txStr];

Precomposed and Decomposed Forms

Some Unicode characters can be represented in two forms, which are decomposed form and precomposed form (precomposed form is also called composite form or composed form). For example, ' パ ' can be represented by one Unicode character (U+30D1, precomposed form) or by two Unicode characters (U+30CF('ハ') + U+309A('°'), decomposed form). Internally, Vectorworks uses Unicode characters in precomposed form. Client code using VW SDK doesn't need to worry about the difference.

Developers need to pay attention to the difference when calling some native Mac functions. In most cases, characters from OS APIs (Mac or Windows) are in the precomposed form. There are some exceptions on Mac. Two of them are APIs handling URLs and plist files. When TXString objects are initiated from objects returned by OS in these areas, ToPrecomposed() can be called to convert decomposed form to precomposed form. If the code needs to return a string in decomposed form, ToDecomposed() can be called to do the conversion before sending it to the OS. For example, SDK file/folder classes convert decomposed strings from Mac APIs to precomposed form right after these calls. Thus, all strings processed and manipulated internally are in precomposed form, and the client code using VW SDK doesn't need to worry about this. (If strings are in different forms, string comparison won't work. In addition, methods like element access operator[] and GetLength() may return different results if strings are in decomposed form.)

Surrogate Pairs

Most Unicode characters can be represented by one UTF-16 character. However, Unicode characters greater than U+FFFF need two UTF-16 characters, called surrogate pairs. For example, Unicode character 'SMILING FACE WITH SMILING EYES' ( 😊, U+1F60A) is represented by 0xD83D and 0xDE0A in UTF-16. Thus, it is possible to have a TXString with invalid UTF-16 characters at the edges after some manipulations, such as Truncate(...). TXString automatically removes invalid UTF-16 characters at the edges during the call to Mid(...), Left(...), Right(...), or Truncate(...). The client code can also call TrimLeftInvalidCharacter(), TrimRightInvalidCharacter(), or TrimInvalidCharacters() manually to remove invalid UTF-16 characters at the edges.

Definition

TXString class is defined in "GSString.X.h".

Constructors and Destructors

    TXString();                     // Default constructor
    TXString(const TXString& src);  // Copy constructor
    TXString(TXString&& src);       // Move constructor
    TXString(const StdUStr& src);   // Copy constructor from StdUStr
    TXString(StdUStr&& src);        // Move constructor from StdUStr

    // From other string type
    TXString(const std::string& src, ETXEncoding e = ETXEncoding::eUTF8);
    TXString(const std::wstring& src);
#if GS_MAC
    TXString(const CFStringRef& src);  // Construct from CFStringRef&
#endif

    // Specify initial size
    explicit TXString(size_t nInitialSize);  // Specify size (size_t version)
    explicit TXString(int nInitialSize);     // Specify size (int version)

    // From a buffer
    TXString(const char* src, ETXEncoding e = ETXEncoding::eUTF8);
    TXString(const char* src, size_t len, ETXEncoding e = ETXEncoding::eUTF8);

    TXString(const unsigned char* src, ETXEncoding e = ETXEncoding::eUTF8);

    TXString(const UCChar* src);
    TXString(const UCChar* src, size_t len);

    TXString(const wchar_t* src);
    TXString(const wchar_t* src, size_t len);
    
    // From a character
    explicit TXString(char ch, size_t count = 1);
    explicit TXString(unsigned char ch, size_t count = 1);
    explicit TXString(UCChar ch, size_t count = 1);
    explicit TXString(wchar_t ch, size_t count = 1);
    
    // Destructor
    virtual ~TXString();

Assignment Operators

    TXString& operator=(const TXString& src);       // Copy assignment operator
    TXString& operator=(TXString&& src);            // Move assignment operator
    TXString& operator=(const std::string& src);    // Assignment from std::string
    TXString& operator=(const std::wstring&src);    // Assignment from std::wstring
#if GS_MAC
    TXString& operator=(const CFStringRef& src);    // Assignment from CFStringRef&
#endif
    
    // From a buffer
    TXString& operator=(const char *src);
    TXString& operator=(const unsigned char* src);
    TXString& operator=(const UCChar* src);
    TXString& operator=(const wchar_t* src);
    
    // From single character
    TXString& operator=(char ch);
    TXString& operator=(unsigned char ch);
    TXString& operator=(UCChar ch);
    TXString& operator=(wchar_t ch);
    TXString& operator=(int codePoint);        // For example: txString = 0x27

Length Related Functions

    size_t GetLength() const;
    size_t GetByteSize() const;
    size_t GetEncodingLength(ETXEncoding e) const;
    
    bool IsEmpty() const;
    
    TXString& SetLength(size_t len);
    TXString& SetLength(size_t len, TXChar ch);
    TXString& Truncate(size_t len);
    TXString& Clear();

Element Access

    TXChar& operator[](ptrdiff_t nIndex);
    TXChar operator[](ptrdiff_t nIndex) const;
    TXChar& GetAt(size_t nIndex);
    TXChar GetAt(size_t nIndex) const;
    TXChar& GetLast();
    TXChar GetLast() const;
    TXString& SetAt(size_t nIndex, TXChar ch);

Concatenation

    // Extends string from another TXString object
    TXString& operator+=(const TXString& src);
    
    // Extends string from character buffer
    TXString& operator+=(const char* src);           // UTF-8
    TXString& operator+=(const unsigned char* src);  // UTF-8
    TXString& operator+=(const UCChar* src);
    TXString& operator+=(const wchar_t* src);
    
    // Extends string by one character
    TXString& operator+=(char ch);
    TXString& operator+=(unsigned char ch);
    TXString& operator+=(UCChar ch);
    TXString& operator+=(wchar_t ch);
    TXString& operator+=(int n);  // Unicode code point, for example: 0x63
    
    // String concatenation by using '<<'
    TXString& operator<<(const TXString& src);
    
    // Extends string from character buffer
    TXString& operator<<(const char *src);            // UTF-8
    TXString& operator<<(const unsigned char* src);   // UTF-8
    TXString& operator<<(const UCChar* src);
    TXString& operator<<(const wchar_t* src);
    
    // Extends string by one character
    TXString& operator<<(char ch);
    TXString& operator<<(unsigned char ch);
    TXString& operator<<(UCChar ch);
    TXString& operator<<(wchar_t ch);
    
    // Append a number as string
    TXString& operator<<(Sint32 number);
    TXString& operator<<(Sint64 number);
    TXString& operator<<(Uint32 number);
    TXString& operator<<(Uint64 number);
    TXString& operator<<(double number);
#if GS_MAC
    TXString& operator<<(size_t number);     // size_t is different from Uint64 on the mac
#endif
    TXString& operator<<(const GSHandle h);  // as number

Insertion and Deletion

    // Insert another TXString at position 'pos'.
    TXString& Insert(size_t pos, const TXString& src);
    
    // Insert one buffer at position 'pos'.
    TXString& Insert(size_t pos, const char* src);
    TXString& Insert(size_t pos, const unsigned char* src);  // UTF-8
    TXString& Insert(size_t pos, const UCChar* src);
    TXString& Insert(size_t pos, const wchar_t* src);
    
    // Insert one character 'ch' at position 'pos'.
    TXString& Insert(size_t pos, char ch);
    TXString& Insert(size_t pos, unsigned char ch);
    TXString& Insert(size_t pos, UCChar ch);
    TXString& Insert(size_t pos, wchar_t ch);
    TXString& Insert(size_t pos, int ch);                    // e.g. 0xA5, '¥'
    
    // Delete characters starting from 'pos' for 'len' characters.
    TXString& Delete(size_t pos, size_t len = (size_t) -1);
    
    // Delete the last character
    TXString& DeleteLast();
    
    // Trims white spaces (' ', '\t') or invalid chars
    TXString& TrimLeft();
    TXString& TrimRight();
    TXString& Trim();

    TXString& TrimLeftInvalidCharacter();
    TXString& TrimRightInvalidCharacter();
    TXString& TrimInvalidCharacters();

Replacement, Conversion, Reversion

    // Replaces all 'oldStr' with 'newSTr'.
    TXString& Replace(const TXString& oldStr, const TXString& newStr, bool bIgnoreCase = false);
    
    // Upper case and lower case conversion
    TXString& MakeUpper();
    TXString& MakeLower();
    
    // Reverse the string.
    TXString& MakeReverse();
    
    // Conversion to a Unicode normalization form
    TXString& ToPrecomposed();
    TXString& ToDecomposed();

Getting Data and Casting

    // Returns const pointer to the TXChar buffer.
    const TXChar* GetData() const;
    const TXChar* GetTXCharPtr() const;
    
    // Casting operators
    operator const char*() const;           // UTF-8
    operator const unsigned char*() const;  // UTF-8
    operator const UCChar*() const;         // Unsigned short, UTF-16
    operator const wchar_t*() const;        // wchar_t: Win:UTF-16, Mac:UTF-32
    
    // Casting operators in function form.
    const char* GetCharPtr() const { return (operator const char*()); }
    const unsigned char* GetUCharPtr() const { return (operator const unsigned char*()); }
    const UCChar* GetUCCharPtr() const { return (operator const UCChar*()); }
    const wchar_t* GetWCharPtr() const { return (operator const wchar_t*()); }
    
    // Returns a std string or wstring
    std::string GetStdString(ETXEncoding e = ETXEncoding::eUTF8) const;
    std::wstring GetStdWString() const;
#if GS_MAC
    CFStringRef GetCFStringRef() const;
#endif

Copying Data into External Buffer

    // Note: 'bufSize' is the size of the buffer in bytes. For example, "xyz" needs four
    // bytes to include '\0' at the end.

    void CopyInto(char* dst,
                  size_t bufSize,
                  ETXEncoding e = ETXEncoding::eUTF8) const;

    void CopyInto(unsigned char* ps,
                  size_t bufSize,
                  ETXEncoding e = ETXEncoding::eUTF8) const;
    
    void CopyInto(UCChar* dst, size_t bufElemSize) const;

    void CopyInto(wchar_t* dst, size_t bufElemSize) const;

Searching Functions

    ptrdiff_t Find(const TXString &subStr, size_t posFirst = 0, bool bIgnoreCase = false) const;
    ptrdiff_t Find(int ch, size_t posFirst = 0, bool bIgnoreCase = false) const;
    ptrdiff_t Find(char ch, size_t posFirst = 0, bool bIgnoreCase = false) const;
    
    ptrdiff_t ReverseFind(const TXString &subStr, size_t posLast = -1, bool bIgnoreCase = false) const;
    ptrdiff_t ReverseFind(int ch, size_t posLast = -1, bool bIgnoreCase = false) const;
    ptrdiff_t ReverseFind(char ch, size_t posLast = -1, bool bIgnoreCase = false) const;
    
    ptrdiff_t FindOneOf(const TXString &charSet, size_t posFirst = 0) const;
    ptrdiff_t ReverseFindOneOf(const TXString &charSet, size_t posLast = -1) const;
    
    ptrdiff_t FindNotOneOf(const TXString &charSet, size_t posFirst = 0) const;
    ptrdiff_t ReverseFindNotOneOf(const TXString &charSet, size_t posLast = -1) const;

Surrogate Functions

    bool SurrogatePairAt(size_t nIndex) const;
    bool HasSurrogatePair() const;

Creating Substring

    TXString Mid(size_t nFirst, size_t len = -1) const;
    TXString Left(size_t len) const;
    TXString Right(size_t len) const;

Conversion to and from Numerics

    Sint32 atoi() const;
    Sint64 atoi64() const;
    Real64 atof() const;
    TXString& itoa(Sint64 value);
    TXString& ftoa(Real64 value);
    TXString& ftoa(Real64 value, Sint32 precision);
    static TXString ToStringInt(Sint64 value);
    static TXString ToStringInt(Sint64 value, Sint32 width, wchar_t paddingChar);
    static TXString ToStringReal(Real64 value);
    static TXString ToStringReal(Real64 value, Sint32 precision, bool fixed=true);
    template<typename T>
    static TXString ToString(T value);
    template<typename T>
    static TXString ToStringHex(T value, bool upperCase = true, size_t symbolsCnt = size_t(-1));

Checking TXChar Types

    static bool IsPunctuation(TXChar aTXChar);
    static bool IsWhitespace(TXChar aTXChar);

Comparison Methods

    // Equality functions
    bool Equal(const TXString &str) const;
    bool EqualNoCase(const TXString &str) const;
    
    // Comparison functions
    Sint32 Compare(const TXString &str) const;
    Sint32 CompareNoCase(const TXString &str) const;

Formating

TXString::Format and static TXString::Formatted can be used to generate formatted strings. These functions require known types to be used:

  • short, unsigned short
  • int, unsigned int
  • long, unsigned long
  • long long, unsigned long long
  • double
  • const char
  • const char* -- a UTF-8 encoded string
  • const wchar_t
  • const wchar_t* -- this type depends on the OS, UTF-16 on Windows and UTF-32 on Mac.
  • const void* -- a generic pointer
  • TXString

They support the % markers: d, i, u, o, x, X, f, F, e, E, g, G, a, A, c, s, p, n

Related Non-member Functions

// Comparison operators
bool operator==(const TXString& lhs, const TXString& rhs);
bool operator==(const TXString& lhs, const char* rhs);
bool operator==(const char* lhs, const TXString& rhs);
bool operator==(const TXString& lhs, const TXChar* rhs);
bool operator==(const TXChar* lhs, const TXString& rhs);

bool operator!=(const TXString& lhs, const TXString& rhs);
bool operator!=(const TXString& lhs, const char* rhs);
bool operator!=(const char* lhs, const TXString& rhs);
bool operator!=(const TXString& lhs, const TXChar* rhs);
bool operator!=(const TXChar* lhs, const TXString& rhs);

bool operator<=(const TXString& lhs, const TXString& rhs);
bool operator>=(const TXString& lhs, const TXString& rhs);

bool operator<(const TXString& lhs, const TXString& rhs);
bool operator>(const TXString& lhs, const TXString& rhs);

// Plus operator
TXString operator+(const TXString& lhs, const TXString& rhs);
TXString operator+(const TXString& lhs, TXChar rhs);
TXString operator+(TXChar lhs, const TXString& rhs);
TXString operator+(const TXString& lhs, const TXChar* rhs);
TXString operator+(const TXChar* lhs, const TXString& rhs);

// Non-member swap function
void swap(TXString& lhs, TXString& rhs);

Iterators

TConstForwardIterator

class TConstForwardIterator
{
public:
	TConstForwardIterator(const TXString &str, int nStart=0);
	TConstForwardIterator& operator++();
	TConstForwardIterator& operator--();
	operator bool() const;
	bool operator==(char ch) const;
	int GetPosition() const;
	char GetChar() const;
	char GetNextChar() const;
	char GetPrevChar() const;
};

TConstReverseIterator

class TConstReverseIterator
{
public:
	TConstReverseIterator(const TXString &str);
	TConstReverseIterator& operator++();
	TConstReverseIterator& operator--();
	operator bool() const;
	bool operator==(char ch) const;
	int GetPosition() const;
	char GetChar() const;
	char GetNextChar() const;
	char GetPrevChar() const;
};

TForwardIterator

class TForwardIterator : public TConstForwardIterator
{
public:
	TForwardIterator(const TXString &str, int nStart=0);
	TXString& operator*() const;
	TXString* operator->() const;
};

TReverseIterator

class TReverseIterator : public TConstReverseIterator
{
public:
	TReverseIterator(const TXString &str);
	TXString& operator*() const;	
	TXString* operator->() const;
};

Displaying String Content in Xcode Debug Area

TXString uses a C++ STL container to store string content. Xcode displays the container information in a way that is difficult to read the string content. Since LLDB debugger provides the entire API as Python functions (LLDB Data Formatters), we can use this feature to display string content in a clear format. In this example, two files are created in the user folder (/users/yourname/). One is ".lldbinit" and the other is "lldb_vectorworks.py".

.lldbinit

command script import ~/lldb_vectorworks.py

lldb_vectorworks.py

#=========================================================================================
# lldb_vectorworks.py
# The following code is for displaying TXString content in Xcode debug area.

#=========================================================================================
import sys
import lldb
import lldb.formatters.Logger

CATEGORY_NAME = "vectorworks"

#=========================================================================================
# For displaying StdUStr summary in Xcode
def StdUStrSummary(valobj,internal_dict):
	middle = valobj.GetChildAtIndex(0).GetChildAtIndex(0).GetChildAtIndex(0).GetChildAtIndex(0)
	__s = middle.GetChildAtIndex(1)
	modeAndSize = __s.GetChildAtIndex(0).GetChildAtIndex(0).GetValueAsUnsigned(0)
	
	# String to be returned later.
	retStr = u'u"'
	
	if (modeAndSize & 1) == 0:  # Short/static form
		size = (modeAndSize >> 1)
		
		# Current max array size is 11. If size is greater than 11, this object is not 
		# initialized and the content should be empty.
		if size < 12:	
			txCharBuf = __s.GetChildAtIndex(1).GetPointeeData(0, size).uint16
		
			for i in range(size):
				if txCharBuf[i] == 0:
					break;
				retStr = retStr + unichr(txCharBuf[i])
			
	else:  # Long/dynamic form
		__l = middle.GetChildAtIndex(0)
		
		# We only show the first 1000 characters.
		size = __l.GetChildAtIndex(1).GetValueAsUnsigned(0)
		if size > 1000:
			size = 1000
		txCharBuf = __l.GetChildAtIndex(2).GetPointeeData(0, size).uint16
		
		for i in range(size):
			if txCharBuf[i] == 0:
				break;
			retStr = retStr + unichr(txCharBuf[i])
			
	retStr = retStr + u'"'
	
	return retStr.encode('utf-8')

#=========================================================================================
# For displaying TXString summary in Xcode
def TXStringSummary(valobj,internal_dict):
	return StdUStrSummary(valobj.GetChildMemberWithName('stdUStr'), internal_dict)

#=========================================================================================
def __lldb_init_module(debugger, dict):
	reload(sys)
	sys.setdefaultencoding('utf-8')

	# StdUStr and TXString
	debugger.HandleCommand('type summary add -F lldb_vectorworks.StdUStrSummary StdUStr --category %s' % CATEGORY_NAME)
	debugger.HandleCommand('type summary add -F lldb_vectorworks.TXStringSummary TXString --category %s' % CATEGORY_NAME)

	# Enable the vectorworks category
	debugger.HandleCommand("type category enable %s" % CATEGORY_NAME)
	
#=========================================================================================

See Also

SDK:Vectorworks 2018 Unicode