Esempio n. 1
0
// Convert a nnn.nnn.nnn.nnn ip address string into an array of 4 unsigned
//   chars.
// Returns FALSE on error otherwise TRUE
UtlBoolean OsUtil::convertIpAddressToOctets(const char* ipAddr, unsigned char octets[])
{
        UtlBoolean bSuccess = FALSE ;

        // Make sure the data is well formed before attempting...
        if (OsSocket::isIp4Address(ipAddr)){
                int      index = 0 ;
                int      lastIndex = 0 ;
                int      i ;

                // The data looks ok, so blindly parse away...
                UtlString strTest(ipAddr) ;
                for(i=0; (i<4) && (lastIndex != -1); i++) {
                        if (i > 0) {
                                index = strTest.index(".", lastIndex) ;
                                if (index != -1)
                                        index++ ;
                        }
                        if (index != -1) {
                                octets[i] = (unsigned char) strtoul(strTest(index, strTest.length()).data(), NULL, 10) ;
                        }
                        lastIndex = index ;
                }
                bSuccess = TRUE ;
                strTest.remove(0);
        }

        return bSuccess ;
}
Esempio n. 2
0
void stringTest::DoExecute()
{
	char testChar[256] = {'a', 'b'};

	std::string strTest(testChar, _countof(testChar));

	std::cout << strTest.c_str() << std::endl;

	return ;
}
Esempio n. 3
0
File: main.cpp Progetto: CCJY/coliru
int main()
{
    ConditionTree oTree;

    Parser<> parser(oTree);

    std::string strTest("limit5minutes");

    std::string::const_iterator it_begin(strTest.begin());
    std::string::const_iterator it_end(strTest.end());

    bool result = phrase_parse(it_begin, it_end, parser, ascii::space);
}
Esempio n. 4
0
TEST( String, normal, off )
{
	const char* str = "THIS::IS::A::TEST";

    {
        ex::string_t str1;
        ex::string_t str2("");
        ex::string_t str3("");

        CHECK( str1 == ex::string_t::null );
        CHECK( str2 == str3 );
        CHECK( str1 == str2 );
    }

    {
        ex::string_t str1(str);
		ex::string_t str2 = str1.left( str1.findFirstOf("::") );
		ex::string_t str3 = str1.right( str1.findFirstOf("::")+strlen("::") );

        printf ("str1: %s\n", str1.c_str());
        printf ("str2: %s\n", str2.c_str());
        printf ("str3: %s\n", str3.c_str());
    }

    {
        ex::string_t str1(str);
        ex::string_t str2(str, 3);

        const char* str_1 = str1.c_str();
        const char* str_2 = str2.c_str();
        printf ("str_1: %d", ex::str::len(str_1));
        printf ("str_2: %d", ex::str::len(str_2));

        char str_3[1024];
        ex::mem::set( str_3, 1, sizeof(char)*1024 );
        ex::str::ncpy( str_3, 1024, str, ex::str::len(str)+1 );

        printf ("str_1: %s", str_1);
        printf ("str_2: %s", str_2);
        printf ("str_3: %s", str_3);
    }

    {
        char test[5] = { 'h', 'e', 'l', 'l', 'o' };
        const char* test2 = "hello";
        printf ( "len:%d, str:%s\n", ex::str::len(test2), test2 );

        ex::string_t strTest ( test, 5 );
        printf ( "len:%d, str:%s\n", strTest.size(), strTest.c_str() );
    }
}
Esempio n. 5
0
void OpenPakFile(const char *filename)
{
	int			i;
	char		*str1, *str2;
	DIRECTORY	*dummy;

	if(!pakopen)
		paktextures = NULL;

	HavePakColormap = false;

  Str strTest(filename);
  strTest.MakeLower();
  if (strTest.Find("pk3") >= 0 || strTest.Find("zip") >= 0)
  {
    pakopen = g_bPK3 = OpenPK3(filename);
    return;
  }


	if((pakfile[m_nPAKIndex] = OpenFileReadMagic(filename, &f_type)) == NULL)
	{
    //FIXME: error routine
		//Sys_Printf("ERROR: Could not open %s", filename);
		return;
	}
	if(f_type != FTYPE_PACK)
	{
		//Sys_Printf("ERROR: %s is not a valid pack file", filename);
		if(f_type != FTYPE_ERROR)
			fclose(pakfile[m_nPAKIndex]);
		return;
	}
	pakdirptr = ReadPACKDirectory(pakfile[m_nPAKIndex], 0, &dirsize);
	if (pakdirptr == NULL)
	{
		//Sys_Printf("ERROR: Could not read pack directory", filename);
		fclose(pakfile[m_nPAKIndex]);
		return;
	}
	if (dirsize == 0)
	{
		fclose(pakfile[m_nPAKIndex]);
		return;
	}
	for (i = 0; i < dirsize; i++)
	{
		if(!strnicmp("textures/", pakdirptr[i].name, 9))
		{
			dummy = paktextures;
			str1 = pakdirptr[i].name+9;
			while(strchr(str1, '/'))
			{
				str2 = strchr(str1, '/');
				*str2++ = '\0';
					dummy = AddPakDir(dummy==paktextures?&paktextures:&dummy, str1);
				str1 = str2;
			}

			AddToFileListAlphabetized(&(dummy->files), str1, pakdirptr[i].offset, pakdirptr[i].size, true);
		}
		else if(!strnicmp("pics/colormap.pcx", pakdirptr[i].name, 17))
		{
			HavePakColormap = true;
			PakColormapOffset = pakdirptr[i].offset;
			PakColormapSize = pakdirptr[i].size;
		}
	}
	pakopen = true;

}
Esempio n. 6
0
static void test1(RTTEST hTest)
{
    RTTestSub(hTest, "Basics");

#define CHECK(expr) RTTESTI_CHECK(expr)
#define CHECK_DUMP(expr, value) \
    do { \
        if (!(expr)) \
            RTTestFailed(hTest, "%d: FAILED %s, got \"%s\"", __LINE__, #expr, value); \
    } while (0)

#define CHECK_DUMP_I(expr) \
    do { \
        if (!(expr)) \
            RTTestFailed(hTest, "%d: FAILED %s, got \"%d\"", __LINE__, #expr, expr); \
    } while (0)
#define CHECK_EQUAL(Str, szExpect) \
    do { \
        if (!(Str).equals(szExpect)) \
            RTTestIFailed("line %u: expected \"%s\" got \"%s\"", __LINE__, szExpect, (Str).c_str()); \
    } while (0)
#define CHECK_EQUAL_I(iRes, iExpect) \
    do { \
        if (iRes != iExpect) \
            RTTestIFailed("line %u: expected \"%zd\" got \"%zd\"", __LINE__, iExpect, iRes); \
    } while (0)

    RTCString empty;
    CHECK(empty.length() == 0);
    CHECK(empty.capacity() == 0);

    RTCString sixbytes("12345");
    CHECK(sixbytes.length() == 5);
    CHECK(sixbytes.capacity() == 6);

    sixbytes.append(RTCString("678"));
    CHECK(sixbytes.length() == 8);
    CHECK(sixbytes.capacity() >= 9);

    sixbytes.append("9a");
    CHECK(sixbytes.length() == 10);
    CHECK(sixbytes.capacity() >= 11);

    char *psz = sixbytes.mutableRaw();
        // 123456789a
        //       ^
        // 0123456
    psz[6] = '\0';
    sixbytes.jolt();
    CHECK(sixbytes.length() == 6);
    CHECK(sixbytes.capacity() == 7);

    RTCString morebytes("tobereplaced");
    morebytes = "newstring ";
    morebytes.append(sixbytes);

    CHECK_DUMP(morebytes == "newstring 123456", morebytes.c_str());

    RTCString third(morebytes);
    third.reserve(100 * 1024);      // 100 KB
    CHECK_DUMP(third == "newstring 123456", morebytes.c_str() );
    CHECK(third.capacity() == 100 * 1024);
    CHECK(third.length() == morebytes.length());          // must not have changed

    RTCString copy1(morebytes);
    RTCString copy2 = morebytes;
    CHECK(copy1 == copy2);

    copy1 = NULL;
    CHECK(copy1.length() == 0);

    copy1 = "";
    CHECK(copy1.length() == 0);

    CHECK(RTCString("abc") <  RTCString("def"));
    CHECK(RTCString("") <  RTCString("def"));
    CHECK(RTCString("abc") > RTCString(""));
    CHECK(RTCString("abc") != RTCString("def"));
    CHECK_DUMP_I(RTCString("def") > RTCString("abc"));
    CHECK(RTCString("abc") == RTCString("abc"));
    CHECK(RTCString("").compare("") == 0);
    CHECK(RTCString("").compare(NULL) == 0);
    CHECK(RTCString("").compare("a") < 0);
    CHECK(RTCString("a").compare("") > 0);
    CHECK(RTCString("a").compare(NULL) > 0);

    CHECK(RTCString("abc") <  "def");
    CHECK(RTCString("abc") != "def");
    CHECK_DUMP_I(RTCString("def") > "abc");
    CHECK(RTCString("abc") == "abc");

    CHECK(RTCString("abc").equals("abc"));
    CHECK(!RTCString("abc").equals("def"));
    CHECK(RTCString("abc").equalsIgnoreCase("Abc"));
    CHECK(RTCString("abc").equalsIgnoreCase("ABc"));
    CHECK(RTCString("abc").equalsIgnoreCase("ABC"));
    CHECK(!RTCString("abc").equalsIgnoreCase("dBC"));
    CHECK(RTCString("").equals(""));
    CHECK(RTCString("").equals(NULL));
    CHECK(!RTCString("").equals("a"));
    CHECK(!RTCString("a").equals(""));
    CHECK(!RTCString("a").equals(NULL));
    CHECK(RTCString("").equalsIgnoreCase(""));
    CHECK(RTCString("").equalsIgnoreCase(NULL));
    CHECK(!RTCString("").equalsIgnoreCase("a"));
    CHECK(!RTCString("a").equalsIgnoreCase(""));

    copy2.setNull();
    for (int i = 0; i < 100; ++i)
    {
        copy2.reserve(50);      // should be ignored after 50 loops
        copy2.append("1");
    }
    CHECK(copy2.length() == 100);

    copy2.setNull();
    for (int i = 0; i < 100; ++i)
    {
        copy2.reserve(50);      // should be ignored after 50 loops
        copy2.append('1');
    }
    CHECK(copy2.length() == 100);

    /* printf */
    RTCString StrFmt;
    CHECK(StrFmt.printf("%s-%s-%d", "abc", "def", 42).equals("abc-def-42"));
    test1Hlp1("abc-42-def", "%s-%d-%s", "abc", 42, "def");
    test1Hlp1("", "");
    test1Hlp1("1", "1");
    test1Hlp1("foobar", "%s", "foobar");

    /* substring constructors */
    RTCString SubStr1("", (size_t)0);
    CHECK_EQUAL(SubStr1, "");

    RTCString SubStr2("abcdef", 2);
    CHECK_EQUAL(SubStr2, "ab");

    RTCString SubStr3("abcdef", 1);
    CHECK_EQUAL(SubStr3, "a");

    RTCString SubStr4("abcdef", 6);
    CHECK_EQUAL(SubStr4, "abcdef");

    RTCString SubStr5("abcdef", 7);
    CHECK_EQUAL(SubStr5, "abcdef");


    RTCString SubStrBase("abcdef");

    RTCString SubStr10(SubStrBase, 0);
    CHECK_EQUAL(SubStr10, "abcdef");

    RTCString SubStr11(SubStrBase, 1);
    CHECK_EQUAL(SubStr11, "bcdef");

    RTCString SubStr12(SubStrBase, 1, 1);
    CHECK_EQUAL(SubStr12, "b");

    RTCString SubStr13(SubStrBase, 2, 3);
    CHECK_EQUAL(SubStr13, "cde");

    RTCString SubStr14(SubStrBase, 2, 4);
    CHECK_EQUAL(SubStr14, "cdef");

    RTCString SubStr15(SubStrBase, 2, 5);
    CHECK_EQUAL(SubStr15, "cdef");

    /* substr() and substrCP() functions */
    RTCString strTest("");
    CHECK_EQUAL(strTest.substr(0), "");
    CHECK_EQUAL(strTest.substrCP(0), "");
    CHECK_EQUAL(strTest.substr(1), "");
    CHECK_EQUAL(strTest.substrCP(1), "");

    /* now let's have some non-ASCII to chew on */
    strTest = "abcdefßäbcdef";
            // 13 codepoints, but 15 bytes (excluding null terminator);
            // "ß" and "ä" consume two bytes each
    CHECK_EQUAL(strTest.substr(0),   strTest.c_str());
    CHECK_EQUAL(strTest.substrCP(0), strTest.c_str());

    CHECK_EQUAL(strTest.substr(2),   "cdefßäbcdef");
    CHECK_EQUAL(strTest.substrCP(2), "cdefßäbcdef");

    CHECK_EQUAL(strTest.substr(2, 2),   "cd");
    CHECK_EQUAL(strTest.substrCP(2, 2), "cd");

    CHECK_EQUAL(strTest.substr(6),   "ßäbcdef");
    CHECK_EQUAL(strTest.substrCP(6), "ßäbcdef");

    CHECK_EQUAL(strTest.substr(6, 2),   "ß");           // UTF-8 "ß" consumes two bytes
    CHECK_EQUAL(strTest.substrCP(6, 1), "ß");

    CHECK_EQUAL(strTest.substr(8),   "äbcdef");         // UTF-8 "ß" consumes two bytes
    CHECK_EQUAL(strTest.substrCP(7), "äbcdef");

    CHECK_EQUAL(strTest.substr(8, 3),   "äb");          // UTF-8 "ä" consumes two bytes
    CHECK_EQUAL(strTest.substrCP(7, 2), "äb");

    CHECK_EQUAL(strTest.substr(14, 1),   "f");
    CHECK_EQUAL(strTest.substrCP(12, 1), "f");

    CHECK_EQUAL(strTest.substr(15, 1),   "");
    CHECK_EQUAL(strTest.substrCP(13, 1), "");

    CHECK_EQUAL(strTest.substr(16, 1),   "");
    CHECK_EQUAL(strTest.substrCP(15, 1), "");

    /* and check cooperation with find() */
    size_t pos = strTest.find("ß");
    CHECK_EQUAL(strTest.substr(pos), "ßäbcdef");

    /* check find() */
    CHECK_EQUAL_I(strTest.find("f"), 5);
    CHECK_EQUAL_I(strTest.find("f", 0), 5);
    CHECK_EQUAL_I(strTest.find("f", 3), 5);
    CHECK_EQUAL_I(strTest.find("f", 6), 14);
    CHECK_EQUAL_I(strTest.find("f", 9), 14);
    CHECK_EQUAL_I(strTest.substr(pos).find("d"), 6);

    /* split */
    RTCList<RTCString> spList1 = RTCString("##abcdef##abcdef####abcdef##").split("##", RTCString::RemoveEmptyParts);
    RTTESTI_CHECK(spList1.size() == 3);
    for (size_t i = 0; i < spList1.size(); ++i)
        RTTESTI_CHECK(spList1.at(i) == "abcdef");
    RTCList<RTCString> spList2 = RTCString("##abcdef##abcdef####abcdef##").split("##", RTCString::KeepEmptyParts);
    RTTESTI_CHECK_RETV(spList2.size() == 5);
    RTTESTI_CHECK(spList2.at(0) == "");
    RTTESTI_CHECK(spList2.at(1) == "abcdef");
    RTTESTI_CHECK(spList2.at(2) == "abcdef");
    RTTESTI_CHECK(spList2.at(3) == "");
    RTTESTI_CHECK(spList2.at(4) == "abcdef");
    RTCList<RTCString> spList3 = RTCString().split("##", RTCString::KeepEmptyParts);
    RTTESTI_CHECK(spList3.size() == 0);
    RTCList<RTCString> spList4 = RTCString().split("");
    RTTESTI_CHECK(spList4.size() == 0);
    RTCList<RTCString> spList5 = RTCString("abcdef").split("");
    RTTESTI_CHECK_RETV(spList5.size() == 1);
    RTTESTI_CHECK(spList5.at(0) == "abcdef");

    /* join */
    RTCList<RTCString> jnList;
    strTest = RTCString::join(jnList);
    RTTESTI_CHECK(strTest == "");
    strTest = RTCString::join(jnList, "##");
    RTTESTI_CHECK(strTest == "");

    jnList.append("abcdef");
    strTest = RTCString::join(jnList, "##");
    RTTESTI_CHECK(strTest == "abcdef");

    jnList.append("abcdef");
    strTest = RTCString::join(jnList, ";");
    RTTESTI_CHECK(strTest == "abcdef;abcdef");

    for (size_t i = 0; i < 3; ++i)
        jnList.append("abcdef");
    strTest = RTCString::join(jnList);
    RTTESTI_CHECK(strTest == "abcdefabcdefabcdefabcdefabcdef");
    strTest = RTCString::join(jnList, "##");
    RTTESTI_CHECK(strTest == "abcdef##abcdef##abcdef##abcdef##abcdef");

    /* special constructor and assignment arguments */
    RTCString StrCtor1("");
    RTTESTI_CHECK(StrCtor1.isEmpty());
    RTTESTI_CHECK(StrCtor1.length() == 0);

    RTCString StrCtor2(NULL);
    RTTESTI_CHECK(StrCtor2.isEmpty());
    RTTESTI_CHECK(StrCtor2.length() == 0);

    RTCString StrCtor1d(StrCtor1);
    RTTESTI_CHECK(StrCtor1d.isEmpty());
    RTTESTI_CHECK(StrCtor1d.length() == 0);

    RTCString StrCtor2d(StrCtor2);
    RTTESTI_CHECK(StrCtor2d.isEmpty());
    RTTESTI_CHECK(StrCtor2d.length() == 0);

    for (unsigned i = 0; i < 2; i++)
    {
        RTCString StrAssign;
        if (i) StrAssign = "abcdef";
        StrAssign = (char *)NULL;
        RTTESTI_CHECK(StrAssign.isEmpty());
        RTTESTI_CHECK(StrAssign.length() == 0);

        if (i) StrAssign = "abcdef";
        StrAssign = "";
        RTTESTI_CHECK(StrAssign.isEmpty());
        RTTESTI_CHECK(StrAssign.length() == 0);

        if (i) StrAssign = "abcdef";
        StrAssign = StrCtor1;
        RTTESTI_CHECK(StrAssign.isEmpty());
        RTTESTI_CHECK(StrAssign.length() == 0);

        if (i) StrAssign = "abcdef";
        StrAssign = StrCtor2;
        RTTESTI_CHECK(StrAssign.isEmpty());
        RTTESTI_CHECK(StrAssign.length() == 0);
    }

#undef CHECK
#undef CHECK_DUMP
#undef CHECK_DUMP_I
#undef CHECK_EQUAL
}