Exemplo n.º 1
0
	/*************************************************************************
	Return the index of the first character of the word at 'idx'.	
	*************************************************************************/
	String32::size_type TextUtils::getWordStartIdx(const String32& str, String32::size_type idx)
	{
		String32 temp = str.substr(0, idx);

		trimTrailingChars(temp, DefaultWhitespace);

		if (temp.length() <= 1) {
			return 0;
		}

		// identify the type of character at 'pos'
		if (String32::npos != DefaultAlphanumerical.find(temp[temp.length() - 1]))
		{
			idx = temp.find_last_not_of(DefaultAlphanumerical);
		}
		// since whitespace was stripped, character must be a symbol
		else
		{
			idx = temp.find_last_of(DefaultAlphanumerical + DefaultWhitespace);
		}

		// make sure we do not go past end of string (+1)
		if (idx == String32::npos)
		{
			return 0;
		}
		else
		{
			return idx + 1;
		}

	}
Exemplo n.º 2
0
	/*************************************************************************
	Trim all characters from the set specified in \a chars from the end
	of 'str'.	
	*************************************************************************/
	void TextUtils::trimTrailingChars(String32& str, const String32& chars)
	{
		String32::size_type idx = str.find_last_not_of(chars);

		if (idx != String32::npos)
		{
			str.resize(idx + 1);
		}
		else
		{
			str.erase();
		}

	}