int Target::getId() const { auto strId = GetId(); size_t lastNotNumberCharacterIndex = strId.find_last_not_of("0123456789"); int id; std::stringstream stream; stream << strId.substr(lastNotNumberCharacterIndex + 1); stream >> id; return id + 1; }
// Get the root name of a filename ......................................... // TODO: Check if it is really needed FileName FileName::getRoot() const { size_t skip_directories = find_last_of("/") + 1; size_t point = find_first_of(".", skip_directories); if (point == npos) point = length(); size_t root_end = find_last_not_of("0123456789", point - 1); if (root_end + 1 != point) if (point - root_end > FILENAMENUMBERLENGTH) root_end = point - FILENAMENUMBERLENGTH - 1; return substr(0, root_end + 1); }
stream::~stream() { try { auto s = str(); auto pos = s.find_last_not_of(" \t\n\v\f\r"); if (pos != std::string::npos) { s.erase(pos + 1); s.erase(std::remove(s.begin(), s.end(), '\r'), s.end()); logger::get().queue(time_point_, severity_, std::move(s)); } } catch (...) { } }
stdstr & stdstr::TrimRight (const char * chars2remove) { if (!empty()) { std::string::size_type pos = find_last_not_of(chars2remove); if (pos != std::string::npos) { erase(pos+1); } else { erase(begin(), end()); // make empty } } return *this; }
//++ // Details: Remove from either end of *this string the following: " \t\n\v\f\r". // Type: Method. // Args: None. // Return: CMIUtilString - Trimmed string. // Throws: None. //-- CMIUtilString CMIUtilString::Trim() const { CMIUtilString strNew(*this); const char *pWhiteSpace = " \t\n\v\f\r"; const size_t nPos = find_last_not_of(pWhiteSpace); if (nPos != std::string::npos) { strNew = substr(0, nPos + 1); } const size_t nPos2 = strNew.find_first_not_of(pWhiteSpace); if (nPos2 != std::string::npos) { strNew = strNew.substr(nPos2); } return strNew; }
//++ ------------------------------------------------------------------------------------ // Details: Remove from either end of *this string the following: " \t\n\v\f\r". // Type: Method. // Args: None. // Return: CMIUtilString - Trimmed string. // Throws: None. //-- CMIUtilString CMIUtilString::Trim( void ) const { CMIUtilString strNew( *this ); const MIchar * pWhiteSpace = " \t\n\v\f\r"; const MIint nPos = find_last_not_of( pWhiteSpace ); if( nPos != (MIint) std::string::npos ) { strNew = substr( 0, nPos + 1 ).c_str(); } const MIint nPos2 = strNew.find_first_not_of( pWhiteSpace ); if( nPos2 != (MIint) std::string::npos ) { strNew = strNew.substr( nPos2 ).c_str(); } return strNew; }
// Get number from file base name .................................................... int FileName::getNumber() const { size_t skip_directories = find_last_of("/") + 1; size_t point = find_first_of(".", skip_directories); if (point == npos) point = length(); size_t root_end = find_last_not_of("0123456789", point - 1); if (root_end + 1 != point) { if (point - root_end > FILENAMENUMBERLENGTH) root_end = point - FILENAMENUMBERLENGTH - 1; String aux = substr(root_end + 1, point - root_end + 1); return atoi(aux.c_str()); } else return -1; }
CPLString &CPLString::Trim() { static const char szWhitespace[] = " \t\r\n"; const size_t iLeft = find_first_not_of( szWhitespace ); const size_t iRight = find_last_not_of( szWhitespace ); if( iLeft == std::string::npos ) { erase(); return *this; } assign( substr( iLeft, iRight - iLeft + 1 ) ); return *this; }
size_type StringPiece::find_last_not_of(const StringPiece& s, size_type pos) const { if (m_length == 0) return npos; size_type i = std::min(pos, m_length - 1); if (s.m_length == 0) return i; // Avoid the cost of BuildLookupTable() for a single-character search. if (s.m_length == 1) return find_last_not_of(s.m_ptr[0], pos); bool lookup[UCHAR_MAX + 1] = { false }; BuildLookupTable(s, lookup); for (; ; --i) { if (!lookup[static_cast<unsigned char>(m_ptr[i])]) return i; if (i == 0) break; } return npos; }
Path* parsePath(PCWSTR path) { auto_array < WCHAR > extendedPath(MAX_PATH_LEN); Copy(extendedPath, PATH_PREFIX_NT, extendedPath.size()); Cat(extendedPath, FullPath(path).c_str(), extendedPath.size()); ::GetLongPathName(extendedPath, extendedPath, extendedPath.size()); PWSTR tmp = (PWSTR)find_last_not_of((PCWSTR)extendedPath, L"\\ "); if (tmp && (tmp - extendedPath) < (ssize_t)extendedPath.size()) { tmp[1] = STR_END; //erase tailing path separators } Path* Result = nullptr; if (Empty(extendedPath) || !is_exists(extendedPath)) { logError(L"Path \"%s\" is not existing or accessible!\n", extendedPath.data()); } else { { ConsoleColor col(FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN); logInfo(L"Adding directory: "); } logInfo(L"\"%s\"\n", path); Result = new Path(shared_ptr<Path>(), AutoUTF(extendedPath)); } return Result; }
required(hello.find_first_not_of(gm::make_string("elh")) == 4); required(hello.find_first_not_of(hello) == hello.npos); required(hello.find_first_not_of(empty) == 0); required(hello2.find_first_not_of(hello) == 5); // find_last_of required(hello.find_last_of('x') == hello.npos); required(hello.find_last_of('l') == 3); required(hello.find_last_of(empty) == hello.npos); required(hello.find_last_of(gm::make_string("abcdel")) == 3); required(hello.find_last_of(gm::make_string("axcl")) == 3); required(hello2.find_last_of('l') == 9); required(hello2.find_last_of(hello) == 10); // find_last_not_of required(hello.find_last_not_of('x') == hello.size() - 1); required(hello.find_last_not_of(empty) == hello.size() - 1); required(hello.find_last_not_of(gm::make_string("lo")) == 1); required(hello2.find_last_not_of(hello) == 5); // comparison operators required(hello == hello); required(hello != empty); required(hello != hello2); required(hello2 > hello); required(hello < hello2); required(hello > empty); required(hello2 > empty); required(hello >= hello); required(empty <= hello); required(gm::make_string("cat") > gm::make_string("animal"));
size_t DwString::find_last_not_of(const DwString &aStr, size_t aPos) const { return find_last_not_of(&aStr.mRep->mBuffer[aStr.mStart], aPos, aStr.mLength); }
static std::string MakeFunctionNameStandOut(std::string origName) { try // guard against exception, since this is used for exception reporting { auto name = origName; // strip off modifiers for parsing (will be put back at the end) std::string modifiers; auto pos = name.find_last_not_of(" abcdefghijklmnopqrstuvwxyz"); if (pos != std::string::npos) { modifiers = name.substr(pos + 1); name = name.substr(0, pos + 1); } bool hasArgList = !name.empty() && name.back() == ')'; size_t angleDepth = 0; size_t parenDepth = 0; bool hitEnd = !hasArgList; // hit end of function name already? bool hitStart = false; // we parse the function name from the end; escape nested <> and () // We look for the end and start of the function name itself (without namespace qualifiers), // and for commas separating function arguments. for (size_t i = name.size(); i--> 0;) { // account for nested <> and () if (name[i] == '>') angleDepth++; else if (name[i] == '<') angleDepth--; else if (name[i] == ')') parenDepth++; else if (name[i] == '(') parenDepth--; // space before '>' if (name[i] == ' ' && i + 1 < name.size() && name[i + 1] == '>') name.erase(i, 1); // remove // commas if (name[i] == ',') { if (i + 1 < name.size() && name[i + 1] == ' ') name.erase(i + 1, 1); // remove spaces after comma if (!hitEnd && angleDepth == 0 && parenDepth == 1) name.insert(i + 1, " "); // except for top-level arguments, we separate them by 2 spaces for better readability } // function name if ((name[i] == '(' || name[i] == '<') && parenDepth == 0 && angleDepth == 0 && (i == 0 || name[i - 1] != '>') && !hitEnd && !hitStart) // we hit the start of the argument list { hitEnd = true; name.insert(i, " "); } else if ((name[i] == ' ' || name[i] == ':' || name[i] == '>') && hitEnd && !hitStart && i > 0) // we hit the start of the function name { if (name[i] != ' ') name.insert(i + 1, " "); name.insert(i + 1, " "); // in total insert 2 spaces hitStart = true; } } return name + modifiers; } catch (...) { return origName; } }
CL_StringData8::size_type CL_StringData8::find_last_not_of(const CL_StringData8 &s, size_type pos) const { return find_last_not_of(s.data(), pos, s.length()); }
size_t CIString::find_last_not_of(const std::string& str, size_t pos) const { return find_last_not_of(str.data(), pos); }
size_t string::find_last_not_of(const char* s, size_t pos) const { pos = changeVarWhenEuqalNPOS(pos, size(), 1); return find_last_not_of(s, pos, strlen(s)); }
size_t string::find_last_not_of(const string& str, size_t pos) const { pos = changeVarWhenEuqalNPOS(pos, size(), 1); return find_last_not_of(str.begin(), pos, str.size()); }
size_t CIString::find_last_not_of(const char* s, size_t pos) const { return find_last_not_of(s, pos, strlen(s)); }
String String::trimRight ( ) { int pos = find_last_not_of ( " " ); erase ( pos + 1 ); return *this; }
string::size_type string::find_last_not_of<xmlChar>(const xmlChar * s, size_type pos) const { validate_utf8(s+pos, npos); return find_last_not_of(_Convert<xmlChar>::toUTF8(s), pos); }