_tests/fsStrUt/main.cpp

00001 
00002 //---------------------------------------------------------------------------
00003 #include <fs/ut/fsStrUt.h>
00004 
00005 #include <cstdio> // printf
00006 #include <cstring> // strlen
00007 //---------------------------------------------------------------------------
00008 int main()
00009 {
00010     using namespace fs::ut::str;
00011             
00012     //--- MISC STRING OPERATIONS ---
00013     
00014     ::printf("MISC STRING OPERATIONS:\n");
00015     
00016     StrHldr_t Str1("String 1 - copied");
00017     ::printf("%s\n", Str1.GetStr());
00018     
00019     StrHldr_t Str2(L"String 2 - converted from a wide-character string");
00020     ::printf("%s\n", Str2.GetStr());
00021     
00022     WStrHldr_t WStr1(L"Wide String 1 - copied");
00023     ::printf("%S\n", WStr1.GetWStr());
00024 
00025     WStrHldr_t WStr2("Wide String 2 - converted from a single-byte string");
00026     ::printf("%S\n", WStr2.GetWStr());
00027     
00028     //--- STRING TOKENIZER ---
00029     
00030     const char pszString[] = "one, two, \"t h r e e\"";
00031     
00032     ::printf("STRING TOKENIZER: %s\n", pszString);
00033             
00034     Toknzr_t Toknzr(pszString, " ,");
00035     for(const char *pszTok = Toknzr.Next(); pszTok; pszTok = Toknzr.Next())
00036     {
00037         ::printf("token: %s\n", pszTok);
00038     }
00039 
00040     //--- COMMAND LINE PARSER ---
00041     
00042     ::printf("COMMAND LINE PARSER\n");
00043     
00044     CmdLn_t CmdLn("foo -key1 value1 -switch -key2 \"complex value2\"");
00045     
00046     for(int i = 0, n = CmdLn.GetNumToks(); i < n; ++i)
00047         ::printf("token[%d] : %s\n", i, CmdLn.GetTok(i));
00048 
00049     const char *pszVal1 = CmdLn.GetVal("key1");
00050     ::printf("key1: %s\n", pszVal1 ? pszVal1 : "<not found>");
00051     const char *pszVal2 = CmdLn.GetVal("key2");
00052     ::printf("key2: %s\n", pszVal2 ? pszVal2 : "<not found>");
00053     const char *pszVal3 = CmdLn.GetVal("key3");
00054     ::printf("key3: %s\n", pszVal3 ? pszVal3 : "<not found>");
00055     const bool bSwitch = CmdLn.FindTok("-switch") >= 0;
00056     ::printf("-switch: %s\n", bSwitch ? "true" : "false");
00057                 
00058     //---
00059     
00060     return 0;
00061 }
00062 //---------------------------------------------------------------------------
00063 // MISC STRING OPERATIONS:
00064 // String 1 - copied
00065 // String 2 - converted from a wide-character string
00066 // Wide String 1 - copied
00067 // Wide String 2 - converted from a single-byte string
00068 // STRING TOKENIZER: one, two, "t h r e e"
00069 // token: one
00070 // token: two
00071 // token: t h r e e
00072 // COMMAND LINE PARSER
00073 // token[0] : foo
00074 // token[1] : -key1
00075 // token[2] : value1
00076 // token[3] : -switch
00077 // token[4] : -key2
00078 // token[5] : complex value2
00079 // key1: value1
00080 // key2: complex value2
00081 // key3: <not found>
00082 // -switch: true
00083 //---------------------------------------------------------------------------

FipS' Code (Thu Feb 15 22:43:35 2007) - (c) Filip STOKLAS (FipS) - [ www ] [ Guest Book ]