Commit 0c1362a9 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Tomáš Oberhuber
Browse files

Modifications in String documentantion.

Splitting the String examples.
Adding String enum 'SplitSkipEmpty' for the method split.
parent 16b4091d
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -29,9 +29,15 @@ ADD_EXECUTABLE( MathExample MathExample.cpp )
ADD_EXECUTABLE( ParameterContainerExample ParameterContainerExample.cpp )

ADD_EXECUTABLE( StringExample StringExample.cpp )
ADD_CUSTOM_COMMAND( OUTPUT StringExample.out
                    COMMAND StringExample
                    DEPENDS StringExample
                    COMMENT Executing StringExample )
ADD_EXECUTABLE( StringExampleGetAllocatedSize StringExampleGetAllocatedSize.cpp )
ADD_EXECUTABLE( StringExampleGetSize StringExampleGetSize.cpp )
ADD_EXECUTABLE( StringExampleReplace StringExampleReplace.cpp )
ADD_EXECUTABLE( StringExampleSetSize StringExampleSetSize.cpp )
ADD_EXECUTABLE( StringExampleSplit StringExampleSplit.cpp )
ADD_EXECUTABLE( StringExampleStrip StringExampleStrip.cpp )
ADD_EXECUTABLE( TimerExample TimerExample.cpp )

ADD_EXECUTABLE( VectorExample VectorExample.cpp )
+37 −118
Original line number Diff line number Diff line
@@ -8,125 +8,44 @@ using namespace std;

int main( int argc, char* argv[] )
{
    // constructors
    String str1;
    String str2( "string" );
    String str3( str2 );                    // copy constructor
    String str4 = convertToString( 28.4 );  // converts to string
   String emptyString;
   String string1( "string 1" );
   String string2( "string 2" );
   String string3( string2 );
   String string4 = convertToString( 28.4 );

    cout << "str1:" << str1 << endl;
    cout << "str2:" << str2 << endl;
    cout << "str3:" << str3 << endl;
    cout << "str4:" << str4 << endl;
   cout << "empytString = " << emptyString << endl;
   cout << "string1 = " << string1 << endl;
   cout << "string2 = " << string2 << endl;
   cout << "string3 = " << string3 << endl;
   cout << "string4 = " << string4 << endl;

    // functions
    /*int size = str3.getSize();
    cout << "size of string:" << size << "bytes" << endl;
   cout << "emptyString size = " << emptyString.getSize() << endl;
   cout << "string1 size = " << string1.getSize() << endl;
   cout << "string1 length = " << string1.getLength() << endl;

    int alloc_size = str3.getAllocatedSize();
    cout << "alloc_size:" << alloc_size << endl;
   const char* c_string = string1.getString();
   cout << "c_string = " << c_string << endl;

    str1.setSize( 256 );
    size = str3.getSize();
    cout << "size of string:" << size << "bytes" << endl;*/
   cout << " 3rd letter of string1 =" << string1[ 2 ] << endl;

    String setter = "Something new";
    cout << "setter:" << setter << endl;
   cout << " string1 + string2 = " << string1 + string2 << endl;
   cout << " string1 + \"another string\" = " << string1 + "another string" << endl;
   
    const char* getter = str4.getString();
    cout << "getter:" << getter << endl;
   string2 += "another string";
   cout << " string2 = " << string2;
   string2 = "string 2";

    String word( "computer" ) ;
    char third_letter = word[2];
    cout << "third_letter:" << third_letter << endl;
   if( string3 == string2 )
      cout << "string3 == string2" << endl;
   if( string1 != string2 )
      cout << "string1 != string2" << endl;

    // Operators for C Strings
    String a( "hello" );
    a = "bye";
    cout << "a:" << a << endl;
   if( ! emptyString )
      cout << "emptyString is empty" << endl;
   if( string1 )
      cout << "string1 is not empty" << endl;

    String b( "see" );
    b += " you";
    cout << "b:" << b << endl;

    String c;
    c = b + " soon";
    cout << "c:" << c << endl;

    String name( "Jack" );
    if ( name == "Jack" ) cout << "Names are the same." << endl;

    String surname( "Sparrow" );
    if ( surname != "Jones" ) cout << "Surnames are different." << endl;

    // Operators for Strings
    String d1( "Cheese" );
    String d = d1;
    cout << "d:" << d << endl;

    String e( "Mac&" );
    e += d;
    cout << "e:" << e << endl;

    String f;
    String f1("Tim likes ");
    f = f1 + e;
    cout << "f:" << f << endl;

    String num1( "one" );
    String num2( "Anyone", 3);
    if ( num1 == num2 ) cout << "Numbers are the same." << endl;

    String eq1( "a + b" );
    String eq2( "a" );
    if ( eq1 != eq2 ) cout << "Equations are different." << endl;

    // Operators for single characters
    String g;
    g = 'y';
    cout << "g:" << g << endl;

    String h( "x" );
    h += g;
    cout << "h:" << h << endl;

    String i;
    i = convertToString( 'a' ) + 'b';
    cout << "i:" << i << endl;

    String letter1( "u" );
    if ( letter1 == "u" ) cout << "Letters are the same." << endl;

    String letter2( "v" );
    if ( letter2 != "w" ) cout << "Letters are different." << endl;

    // Cast to bool operators
    String full( "string" );
    if ( full ) cout << "String is not empty." << endl;

    String empty;
    if ( !empty ) cout << "String is empty." << endl;

    // replace
    String phrase( "Hakuna matata" );
    String new_phrase = phrase.replace( "a", "u", 2 );
    cout << "new_phrase:" << new_phrase << endl;

    // strip
    String names("       Josh Martin   John  Marley Charles   ");
    String better_names = names.strip();
    cout << "better_names:" << better_names << endl;

    // split
    String dates("3/4/2005;8/7/2011;11/12/2019");
    std::vector<String> list = dates.split(';');
    cout << "list_dates: " << list[0] << ", " << list[1] << ", " << list[2] << endl;

    String cars("opel,mazda,,skoda,");
    std::vector<String> list3 = cars.split(',', true);
    cout << "split with true:" << list3[0] << ", " << list3[1] << ", " << list3[2] << endl;
    std::vector<String> list5 = cars.split(',');
    cout << "split with false:" << list5[0] << ", " << list5[1] << ", " << list5[2] << ", " << list5[3] << endl;

    // save
    File myFile;
+2 −3
Original line number Diff line number Diff line
@@ -7,6 +7,5 @@ using namespace std;
int main()
{
    String str("my world");
    int alloc_size = str.getAllocatedSize();
    cout << "alloc_size:" << alloc_size << endl;
    cout << "Allocated_size = " << str.getAllocatedSize() << endl;
}
 No newline at end of file
+0 −13
Original line number Diff line number Diff line
#include <iostream>
#include <TNL/String.h>

using namespace TNL;
using namespace std;
       
int main()
{
    String str("my world");
    int size = str.getSize();
    cout << "size of string:" << size << "bytes" << endl;
}
+13 −0
Original line number Diff line number Diff line
#include <iostream>
#include <TNL/String.h>

using namespace TNL;
using namespace std;

int main()
{
   String phrase( "Say yes yes yes!" );
   cout << "phrase.replace( \"yes\", \"no\", 1 ) = " << phrase.replace( "yes", "no", 1 ) << endl;
   cout << "phrase.replace( \"yes\", \"no\", 2 ) = " << phrase.replace( "yes", "no", 2 ) << endl;
   cout << "phrase.replace( \"yes\", \"no\", 3 ) = " << phrase.replace( "yes", "no", 3 ) << endl;
}
 No newline at end of file
Loading