bool Gwen::Utility::Strings::To::Floats( const Gwen::String& str, float* f, size_t iCount ) { Strings::List lst; Strings::Split( str, " ", lst ); if ( lst.size() != iCount ) return false; for ( size_t i=0; i<iCount; i++ ) { f[i] = Strings::To::Float( lst[i] ); } return true; }
Vector<const char*>* CreateFontDirectories() { auto directories = new Vector<const char*>; // We'll manually fill our list with common values. directories->PushBack(Strings::Create("/usr/share/fonts")); directories->PushBack(Strings::Create("/usr/local/share/fonts")); // There is also the "~/.fonts" directory... Strings::List<char> homeFontDir; homeFontDir.Append(System::Directories::Home()); homeFontDir.Append("/.fonts"); directories->PushBack(Strings::Create(homeFontDir.c_str())); return directories; }
void Gwen::Utility::Strings::Split( const Gwen::String& str, const Gwen::String& seperator, Strings::List& outbits, bool bLeave ) { int iOffset = 0; int iLength = str.length(); int iSepLen = seperator.length(); size_t i = str.find( seperator, 0 ); while ( i != std::string::npos ) { outbits.push_back( str.substr( iOffset, i-iOffset ) ); iOffset = i + iSepLen; i = str.find( seperator, iOffset ); if ( bLeave ) iOffset -= iSepLen; } outbits.push_back( str.substr( iOffset, iLength-iOffset ) ); }
void Strings::split(Strings::List& out, const std::string& str, const std::string& delimiter) { std::string::size_type beg = 0; std::string::size_type end = 0; do { end = str.find(delimiter, beg); if(end == std::string::npos) end = str.size(); out.push_back( str.substr(beg, end-beg) ); beg = end + delimiter.size(); } while(end < str.size() - 1); }