Пример #1
0
void FCDENode::CleanName(fm::string& n)
{
	size_t length = n.length();
	if (length == 0) return;

	// First character must be alphabetic or the underscore.
	if (n[0] != '_' && !(n[0] >= 'a' && n[0] <= 'z') && !(n[0] >= 'A' && n[0] <= 'Z'))
	{
		n[0] = '_';
	}

	// Other characters must be alpha-numeric or the underscore.
	for (size_t i = 1; i < length; ++i)
	{
		char& c = n[i];
		if (c != '_' && !(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && !(c >= '0' && c <= '9'))
		{
			c = '_';
		}
	}
}
Пример #2
0
	FailIf(IsEquivalent("MY ALTER-EGO", "My alter-ego")); // should not be case-sensitive.
	FailIf(IsEquivalent("Utopia", "Utopian"));
	FailIf(IsEquivalent(fm::string("Greatness"), "Great"));
	FailIf(IsEquivalent("Il est", "Il  est"));
	PassIf(IsEquivalent("Prometheian", "Prometheian\0\0\0")); // This is the only difference allowed between two strings.

	fm::string sz1 = "Test1";
	fm::string sz2("Test1");
	PassIf(IsEquivalent(sz1, sz2)); // Extra verification in case the compiler optimizes out the string differences above.

TESTSUITE_TEST(1, StringTemplate)
	// Not looking to verify all the combinations,
	// but I do want to exercise all the basic functionality.
	fm::string a("TEST1"), b(a), c("TEST2"), d("VIRUSES", 5), e(3, 'C'), f("abc", 10);
	
	PassIf(d.length() == 5);
	PassIf(f.length() == 10);
	PassIf(IsEquivalent(a, "TEST1"));
	PassIf(a == b);
	PassIf(IsEquivalent(a, b));
	PassIf(a[0] == 'T');
	PassIf(IsEquivalent(d, "VIRUS"));
	PassIf(IsEquivalent(e, "CCC"));
	PassIf(a.length() == 5);
	PassIf(a.substr(0, 4) == c.substr(0, 4));
	FailIf(a == c);
	PassIf(a < c);

	e.append("4");
	b.append(a);
	PassIf(IsEquivalent(e, "CCC4"));