public void TrimSubstring(string input, char trimChar, string expected) { var substring = new Substring(input); substring = Substring.Trim(substring, trimChar); Assert.Equal(expected, substring.ToString()); }
//--------------------------------------------------------------------------------------------------------- //--- Test Constructors //--------------------------------------------------------------------------------------------------------- void constructorTest(String inputString, AString result, bool trim) { Substring tok = new Substring(inputString); if (trim) { tok.Trim(); } tok.CopyTo(result); }
public void SubstringConstructor() { AString astr = new AString(); AString res = new AString(); constructorTest("a", res, false); UT_EQ("a", res); constructorTest(" a", res, false); UT_EQ(" a", res); constructorTest("a ", res, false); UT_EQ("a ", res); constructorTest("a b", res, false); UT_EQ("a b", res); constructorTest(" a b", res, false); UT_EQ(" a b", res); constructorTest("a b ", res, false); UT_EQ("a b ", res); constructorTest("a", res, true); UT_EQ("a", res); constructorTest(" a", res, true); UT_EQ("a", res); constructorTest("a ", res, true); UT_EQ("a", res); constructorTest("a b", res, true); UT_EQ("a b", res); constructorTest(" a b", res, true); UT_EQ("a b", res); constructorTest("a b ", res, true); UT_EQ("a b", res); // changing whitespaces { { astr.Clear()._("xy xz abc xy"); Substring subs = new Substring(); subs.Set(astr).Trim("xy ".ToCharArray()); subs.CopyTo(res); UT_EQ("z abc", res); } { Substring subs = new Substring("xy xz abc xy"); subs.TrimStart("xy ".ToCharArray()); subs.TrimEnd("xy ".ToCharArray()); subs.CopyTo(res); UT_EQ("z abc", res); } } // test other constructors { astr.Clear()._(" astring "); UT_TRUE((new Substring()).IsEmpty()); UT_TRUE((new Substring()).IsNull()); UT_EQ("astring", (new Substring(astr)).Trim().ToString()); UT_EQ("str", (new Substring(astr, 2, 3)).ToString()); UT_EQ("", (new Substring(astr, 20, 3)).ToString()); UT_TRUE((new Substring(astr, 20, 3)).IsEmpty()); UT_FALSE((new Substring(astr, 20, 3)).IsNull()); Substring s2 = new Substring(astr); s2.Trim(); UT_EQ("astring", new Substring(s2.ToString()).ToString()); UT_EQ("str", (new Substring((new Substring(astr, 2, 3)))).ToString()); } }
/** **************************************************************************************** * Returns the currently remaining string (without searching for further delimiter * characters).<br> * After this call #HasNext will return false and #Next will return a nulled Substring. * @param trimming Determines if the token is trimmed in respect to the white space * characters defined in field #Whitespaces. * Defaults to \c Whitespaces.Trim. * @return The rest of the original source string, which was not returned by #Next(), yet. ******************************************************************************************/ public Substring GetRest(Whitespaces trimming = enums.Whitespaces.Trim) { // set start, end and end of tokenizer Actual.Set(Rest); if (trimming == enums.Whitespaces.Trim) { Actual.Trim(Whitespaces); } Rest.SetNull(); return(Actual); }