本文整理汇总了C++中StringRange::Empty方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRange::Empty方法的具体用法?C++ StringRange::Empty怎么用?C++ StringRange::Empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringRange
的用法示例。
在下文中一共展示了StringRange::Empty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: normalise_path
static void normalise_path(std::string &result, const StringRange &path)
{
StringRange part(path.begin, path.end);
if (!path.Empty() && (path[0] == '/')) {
result += '/';
++part.begin;
}
const size_t initial_result_length = result.size();
while (true) {
part.end = part.FindChar('/'); // returns part.end if the char is not found
if (part.Empty() || (part == ".")) {
// skip this part
} else if (part == "..") {
// pop the last component
if (result.size() <= initial_result_length)
throw std::invalid_argument(path.ToString());
size_t pos = result.rfind('/');
if (pos == std::string::npos) { pos = 0; }
assert(pos >= initial_result_length);
result.erase(pos);
} else {
// push the new component
if (result.size() > initial_result_length)
result += '/';
result.append(part.begin, part.Size());
}
if (part.end == path.end) { break; }
assert(*part.end == '/');
part.begin = part.end + 1;
part.end = path.end;
}
}
示例2: Read
void IniConfig::Read(const FileSystem::FileData &data)
{
StringRange buffer = data.AsStringRange();
buffer = buffer.StripUTF8BOM();
std::string section_name;
MapType *section_map = 0;
while (!buffer.Empty()) {
StringRange line = buffer.ReadLine().StripSpace();
// if the line is a comment, skip it
if (line.Empty() || (line[0] == '#')) continue;
// check for a section header
if ((line.Size() >= 2) && (line[0] == '[') && (line.end[-1] == ']')) {
++line.begin;
--line.end;
section_name = line.ToString();
section_map = 0;
continue;
}
const char *kend = line.FindChar('=');
// if there's no '=' sign, skip the line
if (kend == line.end) {
Output("WARNING: ignoring invalid line in config file:\n '%.*s'\n", int(line.Size()), line.begin);
continue;
}
StringRange key(line.begin, kend);
StringRange value(kend + 1, line.end);
// strip whitespace
key.end = key.RFindNonSpace();
value = value.StripSpace();
if (!section_map)
section_map = &m_map[section_name];
(*section_map)[key.ToString()] = value.ToString();
}
}
示例3: Float
float IniConfig::Float(const std::string §ion, const std::string &key, float defval) const
{
SectionMapType::const_iterator secIt = m_map.find(section);
if (secIt == m_map.end()) return defval;
MapType::const_iterator it = secIt->second.find(key);
if (it == secIt->second.end()) return defval;
const StringRange val = StringRange(it->second.c_str(), it->second.size()).StripSpace();
if (val.Empty()) return defval;
char *end = 0;
float x = strtod(val.begin, &end);
if (end != val.end) return defval;
return x;
}