本文整理汇总了C++中STR类的典型用法代码示例。如果您正苦于以下问题:C++ STR类的具体用法?C++ STR怎么用?C++ STR使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了STR类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SplitStringT
static void SplitStringT(const STR& str,
const typename STR::value_type s,
bool trim_whitespace,
std::vector<STR>* r)
{
size_t last = 0;
size_t i;
size_t c = str.size();
for(i=0; i<=c; ++i)
{
if(i==c || str[i]==s)
{
size_t len = i - last;
STR tmp = str.substr(last, len);
if(trim_whitespace)
{
STR t_tmp;
TrimWhitespace(tmp, TRIM_ALL, &t_tmp);
r->push_back(t_tmp);
}
else
{
r->push_back(tmp);
}
last = i + 1;
}
}
}
示例2: parse_quoted_fields
int CSV_Parser::parse_quoted_fields(const STR& input_line, STR& field, int& i)
{
/*
Quoted fields are the ones which are enclosed within quotes
For instance - Consider that input_line is - 1997,Ford,E350,"Super, luxurious truck"
An example for a quoted field would be - Super luxurious truck
Another instance being - 1997,Ford,E350,"Super, ""luxurious"" truck"
*/
int j;
field = "";
for(j=i; j<input_line.length(); j++)
{
if(input_line[j] == '"' && input_line[++j] != '"')
{
int k = input_line.find_first_of(CSV_DELIMITER, j);
if(k > input_line.length())
{
k = input_line.length();
}
for(k -= j; k-- > 0; )
{
field += input_line[j++];
}
break;
}
else
{
field += input_line[j];
}
}
return j;
}
示例3: parse
bool CSV_Parser::parse(const STR& input_line, CSV_FIELDS& output_fields)
{
/*
A private method which handles the parsing logic used by both the overloaded public methods
*/
STR field;
int i, j;
if(input_line.length() == 0)
{
return false;
}
i = 0;
do
{
if(i < input_line.length() && input_line[i] == CSV_QUOTE)
{
j = parse_quoted_fields(input_line, field, ++i);
}
else
{
j = parse_normal_fields(input_line, field, i);
}
output_fields.push_back(field);
i = j + 1;
}while(j < input_line.length());
return true;
}
示例4: isPalindrome
/*
* Returns true if the specified string is a Palindrome.
*/
bool isPalindrome( STR str ) {
str.erase( std::remove_if( str.begin(), str.end(), ::isspace ), str.end() );
STR copy = str;
std::reverse( copy.begin(), copy.end() );
return ( strcmp( str.c_str(), copy.c_str() ) == 0 );
}
示例5: distribute
/*
* Returns a vector of strings from the specified string, which has
* been sliced at each position where the delimiter appears.
*/
std::vector<STR> distribute( STR str, CSTR_R delimiter ) {
std::vector<STR> slices;
std::size_t pos = 0;
while ( ( pos = str.find( delimiter ) ) != STR::npos ) {
slices.push_back( str.substr( 0, pos ) );
str.erase( 0, ( pos + delimiter.length() ) );
}
return slices;
}
示例6: scramble
/*
* Returns a scrambled string.
*/
STR scramble( STR str ) {
std::seed_seq sd( str.begin(), str.end() );
std::default_random_engine gen;
for ( int i = str.size() - 1; i > 0; --i ) {
gen.seed( sd );
std::uniform_int_distribution<int> dist( 0, i );
std::swap( str[i], str[dist( gen )] );
}
return str;
}
示例7: ContainsOnlyCharsT
static bool ContainsOnlyCharsT(const STR& input, const STR& characters)
{
for(typename STR::const_iterator iter=input.begin();
iter!=input.end(); ++iter)
{
if(characters.find(*iter) == STR::npos)
{
return false;
}
}
return true;
}
示例8: MD5_Init
STR CCrypt::md5(STR value){
MD5_CTX ctx;
unsigned char buff[MD5_DIGEST_LENGTH];
MD5_Init(&ctx);
MD5_Update(&ctx, value.c_str(), value.length());
MD5_Final(buff, &ctx);
char res[33];
for(int i = 0; i < 16; i++){
sprintf(res+i*2, "%02x", buff[i]);
}
return STR(res);
}
示例9: longest_word
/*
* Returns the longest word found in the specified string.
*/
STR longest_word( CSTR_R str ) {
STR builder = "", longest = "";
for ( unsigned i = 0; i < str.size(); ++i ) {
if ( ( str[i] >= 'A' && str[i] <= 'Z' ) ||
( str[i] >= 'a' && str[i] <= 'z' ) )
builder += str[i];
else
builder.clear();
if ( builder.size() > longest.size() )
longest = builder;
}
return longest;
}
示例10: parse_normal_fields
int CSV_Parser::parse_normal_fields(const STR& input_line, STR& field, int& i)
{
/*
Normal fields are the ones which contain no escaped or quoted characters
For instance - Consider that input_line is - 1997,Ford,E350,"Super, luxurious truck"
An example for a normal field would be - Ford
*/
int j;
j = input_line.find_first_of(CSV_DELIMITER, i);
if(j > input_line.length())
{
j = input_line.length();
}
field = std :: string(input_line, i, j-i);
return j;
}
示例11: SplitStringAlongWhitespaceT
void SplitStringAlongWhitespaceT(const STR& str, std::vector<STR>* result)
{
const size_t length = str.length();
if(!length)
{
return;
}
bool last_was_ws = false;
size_t last_non_ws_start = 0;
for(size_t i=0; i<length; ++i)
{
switch(str[i])
{
// HTML 5定义的空白: space, tab, LF, line tab, FF, or CR.
case L' ':
case L'\t':
case L'\xA':
case L'\xB':
case L'\xC':
case L'\xD':
if(!last_was_ws)
{
if(i > 0)
{
result->push_back(str.substr(last_non_ws_start,
i-last_non_ws_start));
}
last_was_ws = true;
}
break;
default: // 不是空白字符.
if(last_was_ws)
{
last_was_ws = false;
last_non_ws_start = i;
}
break;
}
}
if(!last_was_ws)
{
result->push_back(str.substr(last_non_ws_start,
length-last_non_ws_start));
}
}
示例12: DoIsStringASCII
static bool DoIsStringASCII(const STR& str) {
for (size_t i = 0; i < str.length(); i++) {
typename ToUnsigned<typename STR::value_type>::Unsigned c = str[i];
if (c > 0x7F)
return false;
}
return true;
}
示例13: FileExists
bool FileExists(STR fn){
FILE *F = fopen(fn.c_str(), "r");
if(F){
fclose(F);
return true;
}
return false;
}
示例14: TokenizeT
static size_t TokenizeT(const STR& str,
const STR& delimiters,
std::vector<STR>* tokens) {
tokens->clear();
size_t start = str.find_first_not_of(delimiters);
while (start != STR::npos) {
size_t end = str.find_first_of(delimiters, start + 1);
if (end == STR::npos) {
tokens->push_back(str.substr(start));
break;
}
else {
tokens->push_back(str.substr(start, end - start));
start = str.find_first_not_of(delimiters, end + 1);
}
}
return tokens->size();
}
示例15: TrimStringT
TrimPositions TrimStringT(const STR& input,
const STR& trim_chars,
TrimPositions positions,
STR* output) {
// Find the edges of leading/trailing whitespace as desired.
const size_t last_char = input.length() - 1;
const size_t first_good_char = (positions & TRIM_LEADING) ?
input.find_first_not_of(trim_chars) : 0;
const size_t last_good_char = (positions & TRIM_TRAILING) ?
input.find_last_not_of(trim_chars) : last_char;
// When the string was all whitespace, report that we stripped off whitespace
// from whichever position the caller was interested in. For empty input, we
// stripped no whitespace, but we still need to clear |output|.
if (input.empty() ||
(first_good_char == STR::npos) || (last_good_char == STR::npos)) {
bool input_was_empty = input.empty(); // in case output == &input
output->clear();
return input_was_empty ? TRIM_NONE : positions;
}
// Trim the whitespace.
*output =
input.substr(first_good_char, last_good_char - first_good_char + 1);
// Return where we trimmed from.
return static_cast<TrimPositions>(
((first_good_char == 0) ? TRIM_NONE : TRIM_LEADING) |
((last_good_char == last_char) ? TRIM_NONE : TRIM_TRAILING));
}