5.String Class

ProudNet offers the string classes called Proud.String and Proud.StringA.

The string class allows you easily handle the string such as ATL or STL. For instance,

Proud::String a;  // Empty string
a = L"123";         // Adding values in string.
puts(a);            // a itself provides the string buffer directly.
a += L"abc";        // Adding another string to the string.
if(a == L"123abc")  // Way to compare the contents in the string.
{
    a.Replace(L"123", "def");   // Replacing the contents of string
}

Most of ProudNet APIs use Proud.String while some specific APIs use Proud.StringA.

Reference

5.1Creating a string(format)

With Proud.StringT, you can create a string in the same way of sprintf().

Proud::String a;
a.Format(L"%d %d %s", 1, 2, L"hahaha");
// Now it becomes a = "1 2 hahaha".

5.2Conversion of Unicode and Multibyte

ProudNet is based on Unicode so we actually recommend you to use Unicode in your development project.

But, in any event that you can't use Unicode(like if you have already made programs not based on Unicode), you will be required to convert the input sting of ProudNet to Unicode and the output string of ProudNet to Multibyte code(MBC). The classes that perform this are Proud::StringA2W and Proud::StringW2A.

Proud::StringA2W class helps converting MBC to Unicode and Proud::StringW2A in vice-versa.

Following is an example.

void Foo()

{
    // Converting to MBC from Unicode
    Proud::String a=L"가나다";
    const char* b=Proud::StringW2A(a);
    
    // Converting to Unicode from MBC
    Proud::String c=Proud::StringA2W(b);
}

5.3String Performance

Proud.StringT is also developed in consideration of enhancing performance of string handle. Please refer to its feature below.

Copy-on-write

Proud.StringT's copy-on-write function allows copying the string when it's only necessary. Without using the function, all string data share each other.

Proud::String a = L"abc"; // a contains the string 'abc'
Proud::String b = a; // b shares the same string data of a
Proud::String c = b; // now a,b,c shares the same string data
c = L"bcd"; // a,b still shares the sting data 'abc' but c no longer shares it but owns ‘bcd' separately.
b = c; // b gives up sharing with 'abc' then shares with 'bcd' owned by c

Estimating the length of string

When Proud.StringT.GetLength is called, it returns the pre-estimated string length instantly. Which means it is different from strlen().

5.4Thread safety of string class

Just like int or float, Proud.StringT is not thread-safe. Thus accessing the same string object from several threads is not safe (unless every thread are only reading).

This is same with the string class of either ATL or STL.