本文整理汇总了C++中std::basic_string::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ basic_string::empty方法的具体用法?C++ basic_string::empty怎么用?C++ basic_string::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::basic_string
的用法示例。
在下文中一共展示了basic_string::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: split
std::vector<std::basic_string<T_Char>> split(
const std::basic_string<T_Char>& src,
const std::basic_string<T_Char>& delimit) {
std::vector<std::basic_string<T_Char>> array;
typedef typename std::basic_string<T_Char>::size_type size_type;
typedef typename std::basic_string<T_Char>::const_iterator const_iterator;
std::basic_string<T_Char> tmp;
if (src.empty())
return array;
if (delimit.empty()) {
array.reserve(array.size() + src.size());
for (const_iterator it = src.begin(); it != src.end(); ++it)
array.push_back(std::basic_string<T_Char>(1, *it));
return array;
}
size_type src_pos = 0;
while (src.begin() + src_pos != src.end()) {
size_type fnd_pos = src.find(delimit, src_pos);
if (fnd_pos == std::basic_string<T_Char>::npos) {
array.push_back(std::basic_string<T_Char>(src, src_pos));
break;
}
array.push_back(
std::basic_string<T_Char>(src, src_pos, fnd_pos - src_pos));
src_pos = fnd_pos + delimit.length();
}
return array;
}
示例2: if
std::vector< std::basic_string< CharType > > str_split( std::basic_string< CharType > const & p_str, std::basic_string< CharType > const & p_delims, uint32_t p_maxSplits, bool p_bKeepVoid )
{
typedef std::basic_string< CharType > string_t;
std::vector< string_t > l_arrayReturn;
if ( ! p_str.empty() && ! p_delims.empty() && p_maxSplits > 0 )
{
l_arrayReturn.reserve( p_maxSplits + 1 );
std::size_t l_numSplits = 0;
std::size_t l_pos = 0;
std::size_t l_start = 0;
do
{
l_pos = p_str.find_first_of( p_delims, l_start );
if ( l_pos == l_start )
{
l_start = l_pos + 1;
if ( p_bKeepVoid )
{
l_arrayReturn.push_back( string_t() );
}
}
else if ( l_pos == string_t::npos || l_numSplits == p_maxSplits )
{
string_t remnants = p_str.substr( l_start );
if ( !remnants.empty() || p_bKeepVoid )
{
l_arrayReturn.push_back( remnants );
}
return l_arrayReturn;
}
else
{
l_arrayReturn.push_back( p_str.substr( l_start, l_pos - l_start ) );
l_start = l_pos + 1;
}
//l_start = p_str.find_first_not_of( p_delims, l_start );
++ l_numSplits;
}
while ( l_pos != string_t::npos );
}
return l_arrayReturn;
}
示例3: ShellExecute
Error ShellExecute(const std::basic_string<charT, traits, Allocator>& fileName = std::basic_string<charT, traits, Allocator>(),
const std::basic_string<charT, traits, Allocator>& operation = std::basic_string<charT, traits, Allocator>(),
const std::basic_string<charT, traits, Allocator>& parameters = std::basic_string<charT, traits, Allocator>(),
const std::basic_string<charT, traits, Allocator>& directory = std::basic_string<charT, traits, Allocator>(),
HWND hwnd = HWND(NULL),
show_command showCmd = show_command_normal)
{
const charT * const file = fileName.c_str();
const charT * const op = operation.empty() ? NULL : operation.c_str();
const charT * const params = parameters.empty() ? NULL : parameters.c_str();
const charT * const dir = directory.empty() ? NULL : directory.c_str();
return ShellExecute(hwnd, op, file, params, dir, showCmd);
}
示例4: lock
std::basic_string< char > str_convert< char, wchar_t >( std::basic_string< wchar_t > const & src )
{
std::basic_string< char > dst;
if ( !src.empty() )
{
std::unique_lock< std::mutex > lock( g_conversionMutex );
char * szloc = setlocale( LC_CTYPE, "" );
size_t size = wcstombs( NULL, src.c_str(), 0 ) + 1;
char * buffer = NULL;
{
auto guard = make_block_guard( [&buffer, &size]()
{
buffer = new char[size + 1];
}, [&buffer]()
{
delete [] buffer;
} );
size = std::min( size, wcstombs( buffer, src.c_str(), size ) );
setlocale( LC_CTYPE, szloc );
dst.assign( buffer, buffer + size );
}
}
return dst;
}
示例5: TrimRight
void IO::TrimRight(std::basic_string<charType> & str, const char* chars2remove)
{
if (!str.empty()) { //trim the characters in chars2remove from the right
std::string::size_type pos = 0;
if (chars2remove != NULL) {
pos = str.find_last_not_of(chars2remove);
if (pos != std::string::npos)
str.erase(pos+1);
else
str.erase( str.begin() , str.end() ); // make empty
}
else { //trim space
pos = std::string::npos;
for (int i = str.size()-1; i >= 0; --i) {
if (!isspace(str[i])) {
pos = i;
break;
}
}
if (pos != std::string::npos) {
if (pos+1 != str.size())
str.resize(pos+1);
}
else {
str.clear();
}
}
}
}
示例6: sp
std::basic_string<Ch> encode_char_entities(const std::basic_string<Ch> &s)
{
// Don't do anything for empty strings.
if(s.empty()) return s;
typedef typename std::basic_string<Ch> Str;
Str r;
// To properly round-trip spaces and not uglify the XML beyond
// recognition, we have to encode them IF the text contains only spaces.
Str sp(1, Ch(' '));
if(s.find_first_not_of(sp) == Str::npos) {
// The first will suffice.
r = detail::widen<Ch>(" ");
r += Str(s.size() - 1, Ch(' '));
} else {
typename Str::const_iterator end = s.end();
for (typename Str::const_iterator it = s.begin(); it != end; ++it)
{
switch (*it)
{
case Ch('<'): r += detail::widen<Ch>("<"); break;
case Ch('>'): r += detail::widen<Ch>(">"); break;
case Ch('&'): r += detail::widen<Ch>("&"); break;
case Ch('"'): r += detail::widen<Ch>("""); break;
case Ch('\''): r += detail::widen<Ch>("'"); break;
default: r += *it; break;
}
}
}
return r;
}
示例7: delimiter
std::basic_string<C>
perl_s (std::basic_string<C> const& src, std::basic_string<C> const& e)
{
typedef std::basic_string<C> string;
typedef typename string::size_type size;
if (e.empty ())
return src;
C delimiter (e[0]);
size first = e.find (delimiter);
size middle = e.find (delimiter, first + 1);
size last = e.find (delimiter, middle + 1);
string pattern (e, first + 1, middle - first - 1);
string format (e, middle + 1, last - middle - 1);
//std::cout << pattern << " " << format << std::endl;
boost::basic_regex<C> expr (pattern);
return regex_merge (
src,
expr,
format,
boost::match_default | boost::format_all );
}
示例8:
const std::basic_string<charT>& nan_text() {
static std::basic_string<charT> r;
if (r.empty()) {
std::basic_ostringstream<charT> out;
out << "#NaN#";
r = out.str();
}
return r;
}
示例9: cstr
cstr(const std::basic_string<char_type, CharTraits, Allocator>& s)
{
if (s.empty()) {
clear();
} else {
buf_ = s.c_str();
size_ = s.size();
}
}
示例10: string_compare
inline int string_compare(const std::basic_string<C,T,A>& s, const C* p)
{
if(0 == *p)
{
if(s.empty() || ((s.size() == 1) && (s[0] == 0)))
return 0;
}
return s.compare(p);
}
示例11: EndsWith
bool EndsWith(const std::basic_string<CharT> &lhs, const std::basic_string<CharT> &rhs)
{
if (rhs.empty())
return true;
if (lhs.length() < rhs.length())
return false;
return lhs.compare(lhs.length() - rhs.length(), rhs.length(), rhs) == 0;
}
示例12: escape_argument
std::basic_string<CharType> escape_argument_if_needed(const std::basic_string<CharType>& arg)
{
if (!arg.empty() && !has_escapable_characters(arg))
{
return arg;
}
else
{
return escape_argument(arg);
}
}
示例13:
/** Return true iff `str` is a valid Symbol. */
static inline bool is_valid(const std::basic_string<char>& str) {
if (str.empty() || (str[0] >= '0' && str[0] <= '9')) {
return false; // Must start with a letter or underscore
}
for (size_t i = 0; i < str.length(); ++i) {
if (!is_valid_char(str[i])) {
return false; // All characters must be _, a-z, A-Z, 0-9
}
}
return true;
}
示例14: split
ResultList split(const std::basic_string<CharT> &s,
const std::basic_string<CharT> &delimiter, bool keepEmptyParts = true)
{
ResultList slist;
// If delimiter.empty():
// pos = s.find(delimiter, start);
// pos will be 0.
if (delimiter.empty()) {
slist.push_back(s);
return slist;
}
typename std::basic_string<CharT>::size_type start = 0;
typename std::basic_string<CharT>::size_type pos;
std::basic_string<CharT> part;
if (delimiter.length() == 1) {
CharT ch = delimiter[0];
// Hope that:
// find(std::basic_string<CharT>, CharT ch)
// will be faster than:
// find(std::basic_string<CharT>, std::basic_string<CharT>)
while ((pos = s.find(ch, start)) != s.npos) { // Use strchr/wcschr instead?
part = s.substr(start, pos - start);
if (!part.empty() || keepEmptyParts)
slist.push_back(part);
start = pos + delimiter.length();
}
} else {
while ((pos = s.find(delimiter, start)) != s.npos) { // Use strstr/wcsstr instead?
part = s.substr(start, pos - start);
if (!part.empty() || keepEmptyParts)
slist.push_back(part);
start = pos + delimiter.length();
}
}
if (start != s.length() || keepEmptyParts)
slist.push_back(s.substr(start));
return slist;
}
示例15: PathJoin
std::basic_string<Char> PathJoin(const std::basic_string<Char>& dir, const std::basic_string<Char>& file)
{
if(dir.empty()) return file;
Char c = *(dir.rbegin());
switch(c)
{
case '\\':
case '/':
return dir + file;
}
std::basic_string<Char> ret(dir);
ret.push_back('\\');
ret.append(file);
return ret;
}