[ leka @ 25.03.2002. 12:25 ] @
Na delu SourceForge-a koji se zove "Snippets" sam ovih dana nasao ove dve funkcije koje su poprilicno interesantne, te ih zato ovde pejstujem... Funkcije mozete koristiti u svakom kompajleru, na svim platformama... Ova prva je posebno meni interesantna... Neko ce mozda pitati "cemu to?"... Odgovor je "Mozda nekom treba"! :) Code: // Correct number format for a signed integer // is given by regex [-+]+[0-9]* // '0' to '9' must be continuous in C and C++ // str must be \0-terminated bool is_a_number( const char* str ) { if( *str=='-' || *str=='+' ) ++str; while (*str >= '0' && *str<='9') ++str; // return true if the first nondigit is the end. return (*str=='\0'); } // Using std::string::c_str() is less efficient bool is_a_number ( std::string const& str ) { std::string::iterator si = str.begin(); const std::string::iterator end = str.end(); if( *si=='-' || *si=='+' ) ++si; while ( si != end && (*si>='0' && *si <='9') ) ++si; // return true if the first nondigit is the end. return ( si == end ); } //For wchar_t, substitute L'0' for '0' etc. |