String trim(const String& s) { size_t start = s.find_first_not_of(_(" \t")); size_t end = s.find_last_not_of( _(" \t")); if (start == String::npos) { return String(); } else if (start == 0 && end == s.size() - 1) { return s; } else { return s.substr(start, end - start + 1); } }
void StringUtil::trim(String& str, BOOL left, BOOL right) { static const String delims = " \t\r"; if (right) { str.erase(str.find_last_not_of(delims) + 1); } if (left) { str.erase(0, str.find_first_not_of(delims)); } }
String Common::TrimLeftString(const String& s) { size_t nFirst = s.find_first_not_of(_T(" \t\n\r")); if (String::npos != nFirst) { return s.substr(nFirst); } else { return _T(""); } }
ui32 Tokenizer::tokenize( const String& str, TArray<String>& tokens, const String& delimiters ) { // Skip delimiters at beginning. String::size_type lastPos = str.find_first_not_of( delimiters, 0 ); // find first "non-delimiter". String::size_type pos = str.find_first_of( delimiters, lastPos ); while( String::npos != pos || String::npos != lastPos ) { // Found a token, add it to the vector. String tmp = str.substr( lastPos, pos - lastPos ); if ( !tmp.empty() && ' ' != tmp[ 0 ] ) { tokens.add( tmp ); } // Skip delimiters. Note the "not_of" lastPos = str.find_first_not_of( delimiters, pos ); // Find next "non-delimiter" pos = str.find_first_of( delimiters, lastPos ); } return static_cast<ui32>( tokens.size() ); }
bool Trim(String &Str,LPCWSTR pszSpaces) { if (IsStringEmpty(pszSpaces)) return false; const String::size_type First=Str.find_first_not_of(pszSpaces); if (First==String::npos) return false; Str=Str.substr(First,Str.find_last_not_of(pszSpaces)-First+1); return true; }
static String trim_blank (const String &str) { String::size_type begin, len; begin = str.find_first_not_of (" \t\n\v"); if (begin == String::npos) return String (); len = str.find_last_not_of (" \t\n\v") - begin + 1; return str.substr (begin, len); }
void trim( String& str, bool left/* = true*/, bool right/* = true */) { static const String delims = " \t\r"; if( right ) { str.erase( str.find_last_not_of( delims ) + 1 ); // trim right } if( left ) { str.erase(0, str.find_first_not_of( delims ) ); // trim left } }
/* Trim all spaces from the beginning and the end */ void trim(String& str) { String::size_type pos = str.find_last_not_of(' '); if (pos != String::npos) { str.erase(pos + 1); pos = str.find_first_not_of(' '); if (pos != String::npos) str.erase(0, pos); } else str.clear(); }
bool uri::parse(String const& src) { clear(); // Find protocol prefix String::size_type pos1 = 0, pos2; if((pos1 = src.find(':')) != String::npos) { if(src[pos1 + 1] == '/' && src[pos1 + 2] == '/') { m_prot = src.substr(0, pos1); pos1 += 3; } else { pos1 = 0; } } // Find port separator if((pos2 = src.find(':', pos1)) != String::npos) { // Ensure that the port sep lies before any path seps if(src.find('/', pos1) > pos2) { // Extract host m_host = src.substr(pos1, pos2 - pos1); // Find port end pos1 = pos2 + 1; pos2 = src.find_first_not_of("0123456789", pos1); //String::size_type len = pos2 == String::npos ? pos2 : pos2 - pos1; // Extract port m_port = atoi(src.substr(pos1, pos2 - pos1).c_str()); // Correct pos pos1 = pos2; } } else { // Find end of hostname pos2 = src.find('/', pos1); m_host = src.substr(pos1, pos2 - pos1); } return true; }
/************************************************************************* Trim all characters from the set specified in \a chars from the beginning of 'str'. *************************************************************************/ void TextUtils::trimLeadingChars(String& str, const String& chars) { String::size_type idx = str.find_first_not_of(chars); if (idx != String::npos) { str.erase(0, idx); } else { str.erase(); } }
// Next token ============================================================== String nextToken(const String &str, size_t &i) { String retval; if (i >= str.length()) return retval; int j = str.find_first_not_of(" \t\n", i); if (j == -1) return retval; int k = str.find_first_of(" \t\n", j + 1); if (k == -1) k = str.length(); retval = str.substr(j, k - j + 1); i = k + 1; return retval; }
/************************************************************************* draws wrapped text *************************************************************************/ size_t Font::drawWrappedText(const String& text, const Rect& draw_area, float z, const Rect& clip_rect, TextFormatting fmt, const ColourRect& colours, float x_scale, float y_scale) { size_t line_count = 0; Rect dest_area(draw_area); float wrap_width = draw_area.getWidth(); String whitespace = TextUtils::DefaultWhitespace; String thisLine, thisWord; size_t currpos = 0; // get first word. currpos += getNextWord(text, currpos, thisLine); // while there are words left in the string... while (String::npos != text.find_first_not_of(whitespace, currpos)) { // get next word of the string... currpos += getNextWord(text, currpos, thisWord); // if the new word would make the string too long if ((getTextExtent(thisLine, x_scale) + getTextExtent(thisWord, x_scale)) > wrap_width) { // output what we had until this new word line_count += drawText(thisLine, dest_area, z, clip_rect, fmt, colours, x_scale, y_scale); // remove whitespace from next word - it will form start of next line thisWord = thisWord.substr(thisWord.find_first_not_of(whitespace)); // reset for a new line. thisLine.clear(); // update y co-ordinate for next line dest_area.d_top += getLineSpacing(y_scale); } // add the next word to the line thisLine += thisWord; } // Last line is left aligned TextFormatting last_fmt = (fmt == Justified ? LeftAligned : fmt); // output last bit of string line_count += drawText(thisLine, dest_area, z, clip_rect, last_fmt, colours, x_scale, y_scale); return line_count; }
//----------------------------------------------------------------------------// size_t RenderedStringTextComponent::getNextTokenLength(const String& text, size_t start_idx) { String::size_type word_start = text.find_first_not_of(TextUtils::DefaultWrapDelimiters, start_idx); if (word_start == String::npos) word_start = start_idx; String::size_type word_end = text.find_first_of(TextUtils::DefaultWrapDelimiters, word_start); if (word_end == String::npos) word_end = text.length(); return word_end - start_idx; }
void Configuration::trimWhitespace(String& str) const { static const std::string whitespace = " \t\n\v\f\r\b"; std::string::size_type pos = 0; pos = str.find_first_not_of(whitespace); if (pos == std::string::npos) { str = ""; return; } if (pos != std::string::npos) str.erase(0, pos); pos = str.find_last_not_of(whitespace); if (pos != std::string::npos) str.erase(pos + 1); }
/************************************************************************* return a String containing the the next word in a String. *************************************************************************/ String TextUtils::getNextWord(const String& str, String::size_type start_idx, const String& delimiters) { String::size_type word_start = str.find_first_not_of(delimiters, start_idx); if (word_start == String::npos) { word_start = start_idx; } String::size_type word_end = str.find_first_of(delimiters, word_start); if (word_end == String::npos) { word_end = str.length(); } return str.substr(start_idx, (word_end - start_idx)); }
bool getFirstToken (const String & str, size_t pos, size_t & endpos, String & token, const unicode_char_t * sepChars) { const size_t first_nonspace = str.find_first_not_of ( sepChars, pos ); if (first_nonspace != std::string::npos) { const size_t first_space = str.find_first_of (sepChars, first_nonspace ); if (first_space != std::string::npos) token = str.substr (first_nonspace, first_space - first_nonspace); else token = str.substr (first_nonspace); endpos = first_space; return true; } return false; }
//----------------------------------------------------------------------- StringVector StringUtil::split( const String& str, const String& delims, unsigned int maxSplits) { StringVector ret; // Pre-allocate some space for performance ret.reserve(maxSplits ? maxSplits+1 : 10); // 10 is guessed capacity for most case unsigned int numSplits = 0; // Use STL methods size_t start, pos; start = 0; do { pos = str.find_first_of(delims, start); if (pos == start) { // Do nothing start = pos + 1; } else if (pos == String::npos || (maxSplits && numSplits == maxSplits)) { // Copy the rest of the string ret.push_back( str.substr(start) ); break; } else { // Copy up to delimiter ret.push_back( str.substr(start, pos - start) ); start = pos + 1; } // parse up to next real data start = str.find_first_not_of(delims, start); ++numSplits; } while (pos != String::npos); return ret; }
String MSWindowsClipboardHTMLConverter::findArg( const String& data, const String& name) const { String::size_type i = data.find(name); if (i == String::npos) { return String(); } i = data.find_first_of(":\r\n", i); if (i == String::npos || data[i] != ':') { return String(); } i = data.find_first_of("0123456789\r\n", i + 1); if (i == String::npos || data[i] == '\r' || data[i] == '\n') { return String(); } String::size_type j = data.find_first_not_of("0123456789", i); if (j == String::npos) { j = data.size(); } return data.substr(i, j - i); }
vector<String> StringUtils::Split(const String& str, const String& delims, int32 preserve) { std::vector<String> ret; ret.reserve(preserve ? preserve : 4); unsigned int numSplits = 0; // Use STL methods size_t start, pos; start = 0; do { pos = str.find_first_of(delims, start); if (pos == start) { // Do nothing start = pos + 1; } else if (pos == String::npos) { // Copy the rest of the string ret.push_back( str.substr(start) ); break; } else { // Copy up to delimiter ret.push_back( str.substr(start, pos - start) ); start = pos + 1; } // parse up to next real data start = str.find_first_not_of(delims, start); ++numSplits; } while (pos != String::npos); return ret; }
////////////////////////////////////////////////////////////////////////// // SplitString // Copy from OGRE ////////////////////////////////////////////////////////////////////////// std::vector<String> split_string( const String& str, const String& delims, unsigned int maxSplits) { // static unsigned dl; std::vector<String> ret; unsigned int numSplits = 0; // Use STL methods size_t start, pos; start = 0; do { pos = str.find_first_of(delims, start); if (pos == start) { // Do nothing start = pos + 1; } else if (pos == String::npos || (maxSplits && numSplits == maxSplits)) { // Copy the rest of the string ret.push_back( str.substr(start) ); break; } else { // Copy up to delimiter ret.push_back( str.substr(start, pos - start) ); start = pos + 1; } // parse up to next real data start = str.find_first_not_of(delims, start); ++numSplits; } while (pos != String::npos); return ret; }
String simplify( const String& str ) { String temp; // First, unescape string String straux = unescape( str ); // Remove spaces from the beginning int pos = straux.find_first_not_of( ' ' ); straux.erase( 0, pos ); // Trim the rest of spaces for( unsigned int i = 0 ; i < straux.length( ) ; ) { temp += straux[ i ]; if ( straux[ i ] == ' ' ) { while( straux[ i ] == ' ' ) { i++; } } else { i++; } } // Remove space left at the end of the string // if needed if( temp[ temp.size( ) - 1 ] == ' ' ) { temp.resize( temp.size() - 1 ); } return temp; }
/** Function to convert strings to integers. 1. If any validation is enabled, then only enabled validations are carried. 2. If any validation is suppressed, then all validations are carried execept the suppressed ones. 3. Throws an error if the value is not a decimal or hexadecimal one. @internalComponent @released @param aStrList - List VID values received at command line @param aUnIntList - Received values are validated and put into this container. */ void CmdLineHandler::StringListToUnIntList(StringList& aStrList, UnIntList& aUnIntList) { String tempString; Long64 intValue = 0; while(aStrList.size() > 0) { tempString = aStrList.front(); if(tempString.length() >= 2) //Hex number should start with '0x' { //is this an Hexadecimal number? if((tempString.at(0) == '0') && (tempString.at(1) == 'x')) { tempString = tempString.substr(2); unsigned int location = 0; if(!tempString.empty()) { while(location < tempString.length()) //Ignore proceeding zeros. { if(tempString.at(location) == '0') { location++; continue; } break; } } else { throw ExceptionReporter(INVALIDVIDVALUE,(char*)aStrList.front().c_str()); } tempString = tempString.substr(location); if(tempString.empty() && location != 0) { tempString = '0'; } unsigned int strLength = tempString.length(); if(strLength <= KHexEightByte && strLength > 0) { if(tempString.find_first_not_of(KHexNumber) == String::npos) { aUnIntList.push_back(ReaderUtil::HexStrToInt(tempString)); aStrList.pop_front(); continue; } } else { throw ExceptionReporter(DATAOVERFLOW,(char*)tempString.c_str()); } } } //is this an Decimal number? if(tempString.find_first_not_of(KDecNumber) == String::npos) { intValue = ReaderUtil::DecStrToInt(tempString); if(intValue <= KDecHighValue) { aUnIntList.push_back(intValue); } else { throw ExceptionReporter(DATAOVERFLOW,(char*)tempString.c_str()); } } else { throw ExceptionReporter(INVALIDVIDVALUE,(char*)tempString.c_str()); } aStrList.pop_front(); } }
void ResourcePackerScreen::ProcessFlags(const String & flagsPathname) { File * file = File::Create(flagsPathname.c_str(), File::READ | File::OPEN); if (!file) { Logger::Error("Failed to open file: %s", flagsPathname.c_str()); } char flagsTmpBuffer[4096]; int flagsSize = 0; while(!file->IsEof()) { char c; int32 readSize = file->Read(&c, 1); if (readSize == 1) { flagsTmpBuffer[flagsSize++] = c; } } flagsTmpBuffer[flagsSize++] = 0; currentFlags = flagsTmpBuffer; String flags = flagsTmpBuffer; const String & delims=" "; // Skip delims at beginning, find start of first token String::size_type lastPos = flags.find_first_not_of(delims, 0); // Find next delimiter @ end of token String::size_type pos = flags.find_first_of(delims, lastPos); // output vector Vector<String> tokens; while (String::npos != pos || String::npos != lastPos) { // Found a token, add it to the vector. tokens.push_back(flags.substr(lastPos, pos - lastPos)); // Skip delims. Note the "not_of". this is beginning of token lastPos = flags.find_first_not_of(delims, pos); // Find next delimiter at end of token. pos = flags.find_first_of(delims, lastPos); } if (CommandLineParser::Instance()->GetVerbose()) for (int k = 0; k < (int) tokens.size(); ++k) { Logger::Debug("Token: %s", tokens[k].c_str()); } if (Core::Instance()->IsConsoleMode()) { for (int k = 0; k < (int) tokens.size(); ++k) { String sub = tokens[k].substr(0, 2); if (sub != "--") printf("\n[WARNING: flag %s incorrect]\n", tokens[k].c_str()); } } CommandLineParser::Instance()->SetFlags(tokens); SafeRelease(file); }
void StringUtils::Trim(String& str, const String& delims) { str.erase(str.find_last_not_of(delims)+1); str.erase(0, str.find_first_not_of(delims)); }
//----------------------------------------------------------------------- StringVector StringUtil::tokenise( const String& str, const String& singleDelims, const String& doubleDelims, unsigned int maxSplits) { StringVector ret; // Pre-allocate some space for performance ret.reserve(maxSplits ? maxSplits+1 : 10); // 10 is guessed capacity for most case unsigned int numSplits = 0; String delims = singleDelims + doubleDelims; // Use STL methods size_t start, pos; char curDoubleDelim = 0; start = 0; do { if (curDoubleDelim != 0) { pos = str.find(curDoubleDelim, start); } else { pos = str.find_first_of(delims, start); } if (pos == start) { char curDelim = str.at(pos); if (doubleDelims.find_first_of(curDelim) != String::npos) { curDoubleDelim = curDelim; } // Do nothing start = pos + 1; } else if (pos == String::npos || (maxSplits && numSplits == maxSplits)) { if (curDoubleDelim != 0) { //Missing closer. Warn or throw exception? } // Copy the rest of the string ret.push_back( str.substr(start) ); break; } else { if (curDoubleDelim != 0) { curDoubleDelim = 0; } // Copy up to delimiter ret.push_back( str.substr(start, pos - start) ); start = pos + 1; } if (curDoubleDelim == 0) { // parse up to next real data start = str.find_first_not_of(singleDelims, start); } ++numSplits; } while (pos != String::npos); return ret; }
void StringUtils::TrimLeft(String& str, const String& delims) { str.erase(0, str.find_first_not_of(delims)); }
void trim_punctuation(const String& str, size_t& start, size_t& end) { start = str.find_first_not_of(word_start_chars, start); end = str.find_last_not_of(word_end_chars, min(end,str.size()-1)) + 1; if (start >= end) start = end; }
bool FileUtils::mkdirs( const String &path ) { bool res = false; ASSERT_D( path.length() > 0 ); #if defined(_WINDOWS) || defined(WIN32) TCHAR abspath[_MAX_PATH]; TCHAR drive[_MAX_DRIVE]; TCHAR dir[_MAX_DIR]; TCHAR fname[_MAX_FNAME]; TCHAR ext[_MAX_EXT]; _tsplitpath_s( _tfullpath( abspath, path.c_str(), _MAX_PATH ), drive, dir, fname, ext ); // remember the current drive int curDrive = _getdrive(); // set the current drive _chdrive( toupper(drive[0]) - 'A' + 1 ); // now start parsing out the path and create all directoried in the // heirarchy String createPath; String dirStr(dir); dirStr += fname; StringUtils::trimBoth( FileUtils::PATH_SEP_PAT, dirStr ); StringTokenizer tok(dirStr, FileUtils::PATH_SEP_PAT); while( tok.hasMoreTokens() ) { createPath += FileUtils::PATH_SEP; createPath += tok.getNextToken(); res = FileUtils::mkdir( createPath ); if ( !res ) { break; } } _chdrive( curDrive ); #else // the first step is to figure out where the path // starts. If the path contains a .. or . prefix, then // we have to calculate the start of the creation path // if it does not contain such prefix, then we'll just create // the directories relative to the current working directory String rootPath; String parsePath; String::size_type startPos = path.find_first_not_of( NTEXT("/.") ); if ( startPos != 0 ) { // there was at least one of these delimiters as a prefix String prefixStr( path, 0, startPos ); rootPath = FileUtils::resolve( prefixStr ); if ( rootPath.length() > 0 ) { if ( rootPath[ rootPath.length() - 1 ] != NTEXT('/') ) { rootPath += FileUtils::PATH_SEP; } } parsePath = path.substr( startPos ); } else { // no delimiters, so just parse the path parsePath = path; } StringTokenizer tok( parsePath, FileUtils::PATH_SEP_PAT ); while( tok.hasMoreTokens() ) { rootPath += tok.getNextToken(); rootPath += FileUtils::PATH_SEP; res = FileUtils::mkdir( rootPath ); if ( !res ) { break; } } #endif return res; }
String IOMLCode::encodeBody(shared_ptr<OMLContext> context, const String& text, bool postProcess, bool preserveStartLineSpaces, bool convertCR) { String value = text; if ( (postProcess) && (context->getMode() != omlRenderModeSearch) && (!context->getRow()) ) { // Detect degli url { String protocolsFindLinkOption = context->getPage()->getOption(Options::url_options::protocols_find_link); //String protocolsFindLinkOption = Options::instance()->getOption(Options::url_options::protocols_find_link); //String UrlMatch = _S("(")+getProtocolsFindLinkOption()+_S(")://(\\w*:\\w*@)?[-\\w.]+(:\\d+)?(/([\\w/_.]*(\\?\\S+)?)?)?"); //String UrlMatch = _S("((")+getProtocolsFindLinkOption()+_S(")(\\W+\\S+[^).,:;?\\]\\} \\r\\n$]+))"); //String UrlMatch = _S("(")+protocolsFindLinkOption+_S(")://(\\w*:\\w*@)?[-\\w.]+(:\\d+)?(/([\\w/_.]*(\\?\\S+)?)?)?"); // 0.11: //String UrlMatch = _S("(") + protocolsFindLinkOption + _S(")://\\S+"); // 1.0: String UrlMatch = _S("(") + protocolsFindLinkOption + _S("):[/\?]\\S+"); // La versione sotto sarebbe meglio, ma non funziona, ad esempio con il link seguente: // skype:?chat&blob=iCnRW4EXR0H_funqp8i2FpbcobXxBfFkllPp0s2NMRd_sbDEOEr5Je-RzNUi //String UrlMatch = _S("(")+protocolsFindLinkOption+_S("):\\S+"); String UrlReplace = _S("[url]$0[/url]"); //if(regex_match(value, RegexManager::instance()->getRegex(UrlMatch, true))) value = regex_replace(value, RegexManager::instance()->getRegex(UrlMatch, true), UrlReplace); //String MailMatch = _S("\\b((([A-Za-z0-9$_.+%=-])|%[A-Fa-f0-9]{2})+@(([A-Za-z0-9$_.+!*,;/?:%&=-])|%[A-Fa-f0-9]{2})+\\.[a-zA-Z0-9]{1,4})"); String MailMatch = _S("(\\w+\\.)*\\w+@(\\w+\\.)+[A-Za-z]+"); String MailReplace = _S("[email]$0[/email]"); //if(regex_match(value, RegexManager::instance()->getRegex(MailMatch, true))) value = regex_replace(value, RegexManager::instance()->getRegex(MailMatch, true), MailReplace); } if(value != text) { // Sono stati inseriti tag, ricomputo... return encodeOML(context, value); } } // Risolvo gli escaping value.replace_all(_S("\\["), _S("[")); //value.replace_all(_S("\\]"), _S("]")); // Encoding html value = encode(context, value); if(postProcess) { // Emoticons if( (context->getMode() != omlRenderModeSearch) && (context->getPage() != nullptr) ) { String valueLower = value; valueLower.to_lower(); //const StringMap &emoticons = IdeSystem::instance()->getEmoticons(); //for(StringMap::const_iterator i = emoticons.begin(); i != emoticons.end(); ++i) const OMLManager::Emoticons &emoticons = OMLManager::instance()->getEmoticons(); for(OMLManager::Emoticons::const_iterator i = emoticons.begin(); i != emoticons.end(); ++i) { //const String &code = i->first; shared_ptr<OMLEmoticon> emo = *i; const String &code = emo->getCode(); // Ottimizzazione, se non lo trovo con una 'find' secca sull'equivalente in lower-case, // inutile cercarlo via regex. if(valueLower.find(emo->getCode()) != String::npos) { //const String &name = i->second; const String &name = emo->getName(); String title = getText(context, _S("emoticons.") + name); String url = context->getPage()->getSkin()->getImageUrl(_S("emoticons/")+name+_S(".gif")); String out = String::format(_S(" <img src=\"%S\" alt=\"%S\" title=\"%S\"> ").c_str(), url.c_str(), code.c_str(), title.c_str()); // Se prima o dopo non c' niente, o c' un carattere : String codeRegexQuote = regex_quote(code); // RegEx presa da Invision // $txt = preg_replace( "!(?<=[^\w&;/])$code(?=.\W|\W.|\W$)!ei", "\$this->convert_emoticon('$code', '$image')", $txt ); //String re = _S("!(?<=[^\\w&;/])") + codeRegexQuote + _S("(?=.\\W|\\W.|\\W$)!ei"); //String re = _S("( ")+codeRegexQuote+_S(" |^")+codeRegexQuote+_S(" | ")+codeRegexQuote+_S("$|^")+codeRegexQuote+_S("$)"); // Non sono riuscito a far e il detect dei limiti della stringa, per cui aggiungo due spazi prima e trimmo dopo. value = _S(" ") + value + _S(" "); //String charsEmoBoundary = _S("\\s\\n\\r:),;"); //String re = String::format(_S("(?<=[%S])%S(?=[%S])").c_str(), charsEmoBoundary.c_str(), codeRegexQuote.c_str(), charsEmoBoundary.c_str()); String re = String::format(_S("(?<=[\\s])%S(?=[\\s])").c_str(), codeRegexQuote.c_str()); // URGENT: da ottimizzare con una // shared_ptr<boost::wregex> re = regex_create(regex, nocase); value = regex_replace(value, RegexManager::instance()->getRegex(re, true), out); // Tolgo i due spazi messi sopra value = value.substr(1,value.length()-2); } } } } // Encoding dei \n if ( (context->getMode() == omlRenderModeSearch) || (context->getRow()) ) { value.replace_all(_S("\n"), _S(" ")); } else { if(preserveStartLineSpaces) { for(;;) { String::size_type posCR = value.find(_S("\n")); if(posCR == String::npos) break; String::size_type posFirstNoSpace = value.find_first_not_of(_S(" "), posCR+1); if(posFirstNoSpace == String::npos) posFirstNoSpace = value.length(); String startLineText = value.substr(posCR+1, posFirstNoSpace - (posCR+1)); startLineText.replace_all(_S(" "),_S(" ")); value = value.substr(0,posCR) + _S("<br>") + startLineText + value.substr(posFirstNoSpace); } } else if(convertCR) { value.replace_all(_S("\n"), _S("<br />")); } } // Ulteriore encoding finale di sicurezza XSS, trasformo i '\' in '\'. value.replace_all(_S("\\"),_S("\")); return value; }
String realpath(String const& _path) { String path = (_path); std::replace(path.begin(), path.end(),'\\','/'); const String & delims="/"; // Skip delims at beginning, find start of first token String::size_type lastPos = path.find_first_not_of(delims, 0); // Find next delimiter @ end of token String::size_type pos = path.find_first_of(delims, lastPos); // output vector Vector<String> tokens; while (String::npos != pos || String::npos != lastPos) { // Found a token, add it to the vector. tokens.push_back(path.substr(lastPos, pos - lastPos)); // Skip delims. Note the "not_of". this is beginning of token lastPos = path.find_first_not_of(delims, pos); // Find next delimiter at end of token. pos = path.find_first_of(delims, lastPos); } String result; for (int i = 0; i < (int)tokens.size(); ++i) { if (tokens[i] == String(".")) { for (int k = i + 1; k < (int)tokens.size(); ++k) { tokens[k - 1] = tokens[k]; } i--; tokens.pop_back(); } if (tokens[i] == String("..")) { for (int k = i + 1; k < (int)tokens.size(); ++k) { tokens[k - 2] = tokens[k]; } i-=2; tokens.pop_back(); tokens.pop_back(); } } #ifndef _WIN32 result = "/"; #endif for (int k = 0; k < (int)tokens.size(); ++k) { result += tokens[k]; if (k + 1 != (int)tokens.size()) result += String("/"); } return result; }