本文整理汇总了C++中string_t::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ string_t::empty方法的具体用法?C++ string_t::empty怎么用?C++ string_t::empty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string_t
的用法示例。
在下文中一共展示了string_t::empty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: split_string
void split_string(string_t& source, const string_t& delim, std::list<string_t>& ret)
{
ret.clear();
if (delim.empty() || source.empty())
{
ret.push_back(source);
return ;
}
size_t last = 0;
size_t index = source.find(delim, last);
while (index!=std::string::npos)
{
ret.push_back(source.substr(last, index - last));
last = index + delim.size();
index = source.find(delim, last);
}
if(index - last > 0)
{
ret.push_back(source.substr(last, index - last));
}
}
示例2: _OnTextContentReceived
void cUpdateChecker::_OnTextContentReceived(const std::string& sContent)
{
LOG<<"cUpdateChecker::_OnTextContentReceived"<<std::endl;
// Read the xml document
spitfire::xml::reader reader;
spitfire::document::cDocument document;
spitfire::util::cProcessInterfaceVoid interface;
spitfire::util::PROCESS_RESULT result = reader.ReadFromString(interface, document, sContent);
if (result != spitfire::util::PROCESS_RESULT::COMPLETE) {
LOG<<"cUpdateChecker::_OnTextContentReceived ReadFromString failed for string \""<<sContent<<"\", returning"<<std::endl;
return;
}
//<latest>
// <linux>
// <version>0.8</version>
// <download>http://chris.iluo.net/projects/medusa/medusa.tar.gz</download>
// <page>http://chris.iluo.net/projects/medusa/</page>
// </linux>
//</latest>
spitfire::document::cNode::const_iterator iterLatest(document);
if (!iterLatest.IsValid()) return;
iterLatest.FindChild("latest");
if (!iterLatest.IsValid()) return;
spitfire::document::cNode::const_iterator iterPlatform(iterLatest);
if (!iterPlatform.IsValid()) return;
iterPlatform.FindChild("linux");
if (!iterPlatform.IsValid()) return;
// Get the version
const string_t sVersion = GetContentOfChildNode(iterPlatform, "version");
if (sVersion.empty()) {
LOG<<"cUpdateChecker::_OnTextContentReceived Could not find version node or content, returning"<<std::endl;
return;
}
spitfire::string::cStringParser sp(sVersion);
string_t sMajorVersion;
sp.GetToStringAndSkip(".", sMajorVersion);
const string_t sMinorVersion = sp.GetToEnd();
const int iMajorVersion = spitfire::string::ToUnsignedInt(sMajorVersion);
const int iMinorVersion = spitfire::string::ToUnsignedInt(sMinorVersion);
// Get the page
const string_t sDownloadPage = GetContentOfChildNode(iterPlatform, "page");
if (sDownloadPage.empty()) {
LOG<<"cUpdateChecker::_OnTextContentReceived Could not find page node or content, returning"<<std::endl;
return;
}
// Notify the handler
handler.OnNewVersionFound(iMajorVersion, iMinorVersion, sDownloadPage);
}
示例3: add
void cmdline_t::add(
const string_t& short_name, const string_t& name, const string_t& description,
const string_t& default_value) const
{
if ( name.empty() ||
nano::starts_with(name, "-") ||
nano::starts_with(name, "--"))
{
log_critical("cmdline: invalid option name [" + name + "]");
}
if ( !short_name.empty() &&
(short_name.size() != 1 || short_name[0] == '-'))
{
log_critical("cmdline: invalid short option name [" + short_name + "]");
}
if ( m_impl->find(name) != m_impl->m_options.end())
{
log_critical("cmdline: duplicated option [" + name + "]");
}
if ( !short_name.empty() &&
m_impl->find(short_name) != m_impl->m_options.end())
{
log_critical("cmdline: duplicated option [" + short_name + "]");
}
m_impl->m_options.emplace_back(short_name, name, description, default_value);
}
示例4: write_start_element_with_prefix
void xml_writer::write_start_element_with_prefix(const string_t& elementPrefix, const string_t& elementName, const string_t& namespaceName)
{
#ifdef WIN32
HRESULT hr;
if (FAILED(hr = m_writer->WriteStartElement(elementPrefix.c_str(), elementName.c_str(), namespaceName.empty() ? NULL : namespaceName.c_str())))
{
auto error = GetLastError();
string msg("XML writer WriteStartElement with prefix failed");
log_error_message(msg, error);
throw std::runtime_error(msg);
}
#else
xmlChar* valueXmlName = (xmlChar*) ::odata::utility::conversions::to_utf8string(elementName).c_str();
if (elementPrefix.empty() && namespaceName.empty())
{
xmlTextWriterStartElement(m_writer, valueXmlName);
}
else
{
xmlChar* valueXmlPrefix = elementPrefix.empty() ? NULL : (xmlChar*) ::odata::utility::conversions::to_utf8string(elementPrefix).c_str();
xmlChar* valueXmlNamespace = namespaceName.empty() ? NULL : (xmlChar*) ::odata::utility::conversions::to_utf8string(namespaceName).c_str();
xmlTextWriterStartElementNS(m_writer, valueXmlPrefix, valueXmlName, valueXmlNamespace);
}
#endif
}
示例5: U
pplx::task<std::shared_ptr<UserExists>>
GigaApi::UsersApi::userExists (const string_t& login, const string_t& email /* = U("")*/) const
{
auto uri = api._client.uri (U("userexists"));
if (!login.empty()) {
uri.append_query (U("login"), login);
}
if (!email.empty()) {
uri.append_query (U("email"), email);
}
return api._client.request<UserExists> (methods::GET, uri);
}
示例6: process
void cmdline_t::process(const int argc, const char* argv[]) const
{
string_t current_name_or_short_name;
for (int i = 1; i < argc; ++ i)
{
const string_t token = argv[i];
assert(!token.empty());
if (nano::starts_with(token, "--"))
{
const string_t name = token.substr(2);
if (name.empty())
{
log_critical(strcat("cmdline: invalid option name [", name, "/", token, "]"));
}
m_impl->store(name);
current_name_or_short_name = name;
}
else if (nano::starts_with(token, "-"))
{
const string_t short_name = token.substr(1);
if (short_name.size() != 1)
{
log_critical(strcat("cmdline: invalid short option name [", short_name, "/", token, "]"));
}
m_impl->store(short_name);
current_name_or_short_name = short_name;
}
else
{
const string_t& value = token;
if (current_name_or_short_name.empty())
{
log_critical(strcat("cmdline: missing option before value [", value, "]"));
}
m_impl->store(current_name_or_short_name, value);
current_name_or_short_name.clear();
}
}
if (has("help"))
{
usage();
}
}
示例7: write_attribute_string
void xml_writer::write_attribute_string(const string_t& prefix, const string_t& name, const string_t& namespaceUri, const string_t& value)
{
#ifdef WIN32
HRESULT hr;
if (FAILED(hr = m_writer->WriteAttributeString(prefix.empty() ? NULL : prefix.c_str(),
name.empty() ? NULL : name.c_str(),
namespaceUri.empty() ? NULL : namespaceUri.c_str(),
value.empty() ? NULL : value.c_str())))
{
auto error = GetLastError();
string msg("XML writer WriteAttributeString failed");
log_error_message(msg, error);
throw std::runtime_error(msg);
}
#else
xmlChar* nameXml = (xmlChar*) ::odata::utility::conversions::to_utf8string(name).c_str();
xmlChar* valueXml = (xmlChar*) ::odata::utility::conversions::to_utf8string(value).c_str();
if (prefix.empty() && namespaceUri.empty())
{
xmlTextWriterWriteAttribute(m_writer, nameXml, valueXml);
}
else
{
xmlChar* valueXmlPrefix = prefix.empty() ? NULL : (xmlChar*) ::odata::utility::conversions::to_utf8string(prefix).c_str();
xmlChar* valueXmlNamespace = namespaceUri.empty() ? NULL : (xmlChar*) ::odata::utility::conversions::to_utf8string(namespaceUri).c_str();
xmlTextWriterWriteAttributeNS(m_writer, valueXmlPrefix, nameXml, valueXmlNamespace, valueXml);
}
#endif
}
示例8: OnCompleteCommand
bool Desktop::OnCompleteCommand(const string_t &cmd, int &pos, string_t &result)
{
assert(pos >= 0);
lua_getglobal(g_env.L, "autocomplete");
if( lua_isnil(g_env.L, -1) )
{
lua_pop(g_env.L, 1);
GetConsole().WriteLine(1, "There was no autocomplete module loaded");
return false;
}
lua_pushlstring(g_env.L, cmd.substr(0, pos).c_str(), pos);
HRESULT hr = S_OK;
if( lua_pcall(g_env.L, 1, 1, 0) )
{
GetConsole().WriteLine(1, lua_tostring(g_env.L, -1));
}
else
{
const char *str = lua_tostring(g_env.L, -1);
string_t insert = str ? str : "";
result = cmd.substr(0, pos) + insert + cmd.substr(pos);
pos += insert.length();
if( g_client && !g_client->IsLocal() && !result.empty() && result[0] != '/' )
{
result = string_t("/") + result;
++pos;
}
}
lua_pop(g_env.L, 1); // pop result or error message
return true;
}
示例9: use_value
void statement::use_value(int pos, string_t const& value, bool make_copy)
{
s_.check_error( aux::select(::sqlite3_bind_text, ::sqlite3_bind_text16)
(impl_, pos, value.empty()? 0 : value.c_str(),
static_cast<int>(value.size() * sizeof(char_t)), make_copy? SQLITE_TRANSIENT : SQLITE_STATIC)
);
}
示例10: TokenizeByDelimiters
void Tokenizer::TokenizeByDelimiters(bool enclosed, const TokenRange& range) {
const string_t delimiters = GetDelimiters(range);
if (delimiters.empty()) {
AddToken(kUnknown, enclosed, range);
return;
}
auto char_begin = filename_.begin() + range.offset;
const auto char_end = char_begin + range.size;
auto current_char = char_begin;
while (current_char != char_end) {
current_char = std::find_first_of(current_char, char_end,
delimiters.begin(), delimiters.end());
const TokenRange subrange(std::distance(filename_.begin(), char_begin),
std::distance(char_begin, current_char));
if (subrange.size > 0) // Found unknown token
AddToken(kUnknown, enclosed, subrange);
if (current_char != char_end) { // Found delimiter
AddToken(kDelimiter, enclosed,
TokenRange(subrange.offset + subrange.size, 1));
char_begin = ++current_char;
}
}
ValidateDelimiterTokens();
}
示例11: Parse
bool Anitomy::Parse(string_t filename) {
elements_.clear();
tokens_.clear();
if (options_.parse_file_extension) {
string_t extension;
if (RemoveExtensionFromFilename(filename, extension))
elements_.insert(kElementFileExtension, extension);
}
if (!options_.ignored_strings.empty())
RemoveIgnoredStrings(filename);
if (filename.empty())
return false;
elements_.insert(kElementFileName, filename);
Tokenizer tokenizer(filename, elements_, options_, tokens_);
if (!tokenizer.Tokenize())
return false;
Parser parser(elements_, options_, tokens_);
if (!parser.Parse())
return false;
return true;
}
示例12:
logger_t::logger_t(
string_t const & name,
bool verbose
) :
_prefix( name.empty() ? "" : name + ": " ),
_verbose( verbose )
{
}; // ctor
示例13: add_pair
void WordForm::add_pair(const string_t &k_word, string_t trans_part)
{
if (k_word.empty() || trans_part.empty())
return;
//printf("pair %s %s\n", k_word.c_str(), trans_part.c_str());
char *saveptr;
const char *delim = " \t\n\v";
char *token = strtok_r(&trans_part[0], delim, &saveptr);
base_forms.add(k_word);
while (token) {
for (int i = 0; token[i]; ++i) {
token[i] = tolower(token[i]);
}
add(k_word, token);
//printf("added %s %s\n", k_word.c_str(), p);
token = strtok_r(NULL, delim, &saveptr);
}
}
示例14: ToPlain
char Square::ToPlain(const string_t & str)
{
if (str.empty())
return ToPlain(Blank);
char ch = ToPlain(to_unicode(str).at(0));
if (ch == 0)
return ToPlain(Blank);
return ch;
}
示例15: GetTrackTitle
string_t cPlayListWriter::GetTrackTitle(const cTrack& track) const
{
std::cout<<"cPlayListWriter::GetTrackTitle"<<std::endl;
string_t sFullTitle;
const string_t sTagArtist = track.sArtist;
const string_t sTagTitle = track.sTitle;
if (!sTagArtist.empty() && !sTagTitle.empty()) {
// Use the artist and title
sFullTitle = sTagArtist + TEXT(" - ") + sTagTitle;
} else {
// Either "title" or "artist" is missing, use the file name
sFullTitle = filesystem::GetFileNoExtension(track.sFullPath);
}
return sFullTitle;
}