Google

TOP --> libjdl

class CJdlStringList
    extends CJdlVector < CJdlString > as public

A dynamic list of strings.

Author:
Joe Linoff

Version:
$Id: jdlstringlist.h,v 1.4 1999/06/12 18:26:00 jdl Exp $

Source:
../../libjdl/src/jdlstringlist.h:33

See Also:
CJdlString, CJdlStringListSorter, CJdlVector

Constructors Index

CJdlStringList
[public] Default constructor.
CJdlStringList
[public] Constructor.
CJdlStringList
[public] Copy constructor.
CJdlStringList
[public] Tokenizing constructor.
~CJdlStringList
[public] Destructor.


Methods Index

Append
[public] Append a string to the list.
Append
[public] Append a string list to the list.
BinarySearchFor
[public] Do binary search to see whether the specified string exists in the list. This is only valid for sorted lists.
Copy
[public] Copy.
operator =
[public] Copy operator.
ReadDir
[public] Read the contents of a directory and append it to this list.
SearchFor
[public] Do linear search to see whether the specified string exists in the list.
str
[public] Convert a list to a string.
Tokenize
[public] Tokenize a string and store the substrings in this list.


Constructors

CJdlStringList

public CJdlStringList ( ) ;

Default constructor.

CJdlStringList

public CJdlStringList ( uint size ) ;

Constructor.

Parameters:
size The initial size of the list.

CJdlStringList

public CJdlStringList ( const CJdlStringList & ) ;

Copy constructor.

Parameters:
size The initial size of the list.

CJdlStringList

public CJdlStringList ( const char * str ,
                        const char * sep ) ;

Tokenizing constructor.

The constructor allows you to create a list of tokens from an input string. It is useful for parsing and is similar to the ::strtok() operator in "C".

Sample usage:

      // Parse the tokens that are separated by colons.
      CJdlString str = "fld1:fld2:fld3:fld4::";
      CJdlStringList list(str,":");
      printf("token[0] = '%s'\n",0,token[0].str());
			printf("token[1] = '%s'\n",0,token[1].str());

Parameters:
str Input string.
sep Separator list.

CJdlStringList

public ~ CJdlStringList ( ) ;

Destructor.


Methods

Append

public void Append ( const char * str ) ;

Append a string to the list.

Sample usage:

    #include "jdlstringlist.h"
    static void foo() {
      CJdlStringList list;
      list.Append("this");
      list.Append("that");
      list.Append("the");
      list.Append("other");
      list.Append("zzz");
      list.Append("aaa");
    }

Parameters:
str The string to append.

Append

public void Append ( CJdlStringList & list ) ;

Append a string list to the list.

Sample usage:

    #include "jdlstringlist.h"
    static void foo() {
      CJdlStringList list;
      list.Append("this");
      list.Append("that");
      list.Append("the");
      list.Append("other");
      list.Append("zzz");
      list.Append("aaa");
      CJdlStringList list1;
      list1.Append(list);
    }

Parameters:
list The list to append.

str

public const char * str ( CJdlString & out ,
                          const char * sep = 0 ) const ;

Convert a list to a string.

Sample usage:

    #include "jdlstringlist.h"
    static void foo() {
      CJdlStringList list;
      list.Append("this");
      list.Append("that");
      list.Append("the");
      list.Append("other");
      list.Append("zzz");
      list.Append("aaa");
      CJdlString tmp;
      printf("list contents:",list.str(tmp,"\n\t");
      printf("\n");
    }

Parameters:
out The string that will contain the output.
sep The separator.

Return:
The out string in "C" format for printing.

Tokenize

public void Tokenize ( const char * str ,
                       const char * sep ) ;

Tokenize a string and store the substrings in this list.

Sample usage:

   // Parse the tokens that are separated by colons.
   CJdlString str = "fld1:fld2:fld3:fld4::";
   CJdlStringList list;
   list.Tokenize(str,":");
   printf("token[0] = '%s'\n",0,token[0].str());
   printf("token[1] = '%s'\n",0,token[1].str());

Parameters:
str Input string.
sep Separator list.

ReadDir

public void ReadDir ( const char * dir ,
                      bool sort = true ) ;

Read the contents of a directory and append it to this list.

The file names in the returned list do not have the root directory pre-pended.

An example is shown below:

   CJdlString list;
   list.ReadDir(".");
   for(uint i=0;i<list.Length();i++) {
     printf("file[%03d] = '%s'\n",list[i].str());
   }
 

Parameters:
dir The path to the directory. This is O/S dependent. If the dir string is NULL, it is ignored and no directory processing takes place.
sort If true, sort the list in ascending order with case sensitivity, otherwise do not sort the list. If you wish to sort the list in another way, see the CJdlStringListSorter class.

BinarySearchFor

public bool BinarySearchFor ( const char * str ) const ;

Do binary search to see whether the specified string exists in the list. This is only valid for sorted lists.

Parameters:
str The string to search for.

Return:
True if str is in the list or false otherwise.

SearchFor

public bool SearchFor ( const char * str ) const ;

Do linear search to see whether the specified string exists in the list.

Parameters:
str The string to search for.

Return:
True if str is in the list or false otherwise.

Copy

public void Copy ( const CJdlStringList & list ) ;

Copy.

Parameters:
list The list to copy.

operator =

public CJdlStringList & operator = ( const CJdlStringList & list ) ;

Copy operator.

Parameters:
list The object to copy.

Return:
The CJdlStringList object.

This documentation was generated automatically by the ccdoc tool (version 0.7a).
Click here to submit a bug report or feature request.

Click here to return to the top of the page.