本文整理汇总了C++中StringRange类的典型用法代码示例。如果您正苦于以下问题:C++ StringRange类的具体用法?C++ StringRange怎么用?C++ StringRange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StringRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setString
void Registry::setString(StringRange valueName, StringRange value, Registry::ValueKind kind) {
assert("Empty Registry" && *this);
assert("Invalid Registry::ValueKind" && (kind == ValueKind::string || kind == ValueKind::expandString || kind == ValueKind::multiString));
checkResult(RegSetValueExW(_handle, valueName.c_str(), 0, kind
, reinterpret_cast<const BYTE*>(value.c_str()), value.length() * sizeof(wchar_t)));
}
示例2: _handle
Registry::Registry(StringRange path, bool writable) : _handle(nullptr) {
assert("Empty path" && !path.empty());
int rootKeyNameEnd = String::refer(path).indexOf(L'\\');
StringRange subKeyName = L"";
if (rootKeyNameEnd == -1) {
rootKeyNameEnd = path.length();
} else {
subKeyName = StringRange(path.c_str() + rootKeyNameEnd + 1);
}
if (!rootKeyNameEnd) {
assert("Invalid Registry root key name" && false);
} else if (!String::compare(path, 0, L"HKEY_CLASSES_ROOT", 0, rootKeyNameEnd)) {
*this = Registry::classesRoot();
} else if (!String::compare(path, 0, L"HKEY_CURRENT_CONFIG", 0, rootKeyNameEnd)) {
*this = Registry::currentConfig();
} else if (!String::compare(path, 0, L"HKEY_CURRENT_USER", 0, rootKeyNameEnd)) {
*this = Registry::currentUser();
} else if (!String::compare(path, 0, L"HKEY_LOCAL_MACHINE", 0, rootKeyNameEnd)) {
*this = Registry::localMachine();
} else if (!String::compare(path, 0, L"HKEY_USERS", 0, rootKeyNameEnd)) {
*this = Registry::users();
} else {
assert("Invalid Registry root key name" && false);
}
if (!subKeyName.empty()) {
*this = openKey(subKeyName, writable);
}
}
示例3: 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;
}
}
示例4: createKey
Registry Registry::createKey(StringRange keyName, bool writable) {
assert("Empty Registry" && *this);
assert("Empty keyName" && !keyName.empty());
Registry key;
checkResult(RegCreateKeyExW(_handle, keyName.c_str(), 0, nullptr, REG_OPTION_NON_VOLATILE
, writable ? KEY_ALL_ACCESS : KEY_READ, nullptr, &key._handle, nullptr));
return key;
}
示例5: openKey
Registry Registry::openKey(StringRange keyName, bool writable) const {
assert("Empty Registry" && *this);
assert("Empty kKeyName" && !keyName.empty());
Registry key;
checkResult(RegOpenKeyExW(_handle, keyName.c_str(), 0
, writable ? KEY_ALL_ACCESS : KEY_READ, &key._handle));
return key;
}
示例6: StringRange
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;
}
示例7: setBinary
void Registry::setBinary(StringRange valueName, ArrayRange<const unsigned char> value, Registry::ValueKind kind) {
assert("Empty Registry" && *this);
assert("Invalid Registry::ValueKind" && ValueKind::_validate(kind));
checkResult(RegSetValueExW(_handle, valueName.c_str(), 0, kind
, value.empty() ? nullptr : value.begin(), value.size()));
}
示例8: removeKey
void Registry::removeKey(StringRange keyName, bool recursive) {
assert("Empty Registry" && *this);
assert("Empty keyName" && !keyName.empty());
if (recursive) {
Registry key = openKey(keyName, true);
if (key) {
auto i = NamesIterator(key, true);
while (i) {
key.removeKey(*i, true);
i.refresh();
}
}
}
checkResult(RegDeleteKeyW(_handle, keyName.c_str()));
}
示例9: ValueNotFoundException
vector<unsigned char> Registry::getBinary(StringRange valueName) const {
assert("Empty Registry" && *this);
DWORD type = REG_NONE;
DWORD size = 0;
LONG result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, nullptr, &size);
vector<unsigned char> buffer;
if (result == ERROR_SUCCESS && 0 < size) {
buffer.resize(size);
result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, buffer.data(), &size);
}
if (result == ERROR_FILE_NOT_FOUND) {
throw ValueNotFoundException();
}
checkResult(result);
return buffer;
}
示例10: ValueKindMismatchException
unsigned __int64 Registry::getQword(StringRange valueName) const {
assert("Empty Registry" && *this);
DWORD type = REG_NONE;
DWORD size = 0;
LONG result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, nullptr, &size);
unsigned __int64 value = 0;
if (result == ERROR_SUCCESS) {
if (type != REG_DWORD && size != sizeof(value)) {
throw ValueKindMismatchException();
}
result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, reinterpret_cast<LPBYTE>(&value), &size);
}
if (result == ERROR_FILE_NOT_FOUND) {
throw ValueNotFoundException();
}
checkResult(result);
return value;
}
示例11: while
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();
}
}
示例12: getStringToBuffer
void Registry::getStringToBuffer(StringBuffer& buffer, StringRange valueName) const {
assert("Empty Registry" && *this);
DWORD type = REG_NONE;
DWORD size = 0;
LONG result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, nullptr, &size);
if (result == ERROR_SUCCESS && 0 < size) {
if (type != REG_SZ
&& type != REG_EXPAND_SZ
&& type != REG_MULTI_SZ) {
throw ValueKindMismatchException();
}
int length = size / sizeof(wchar_t);
buffer.reserveAdditionally(length);
result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, &type, reinterpret_cast<LPBYTE>(buffer.end()), &size);
buffer.expandLength(length - 1);
}
if (result == ERROR_FILE_NOT_FOUND) {
throw ValueNotFoundException();
}
checkResult(result);
}
示例13: ParseInfo
void DistanceFieldFont::ParseInfo(const StringRange &line)
{
std::stringstream ss(line.ToString());
std::string token;
while (ss >> token != 0) {
std::pair<std::string, std::string> pair;
split_token(token, pair);
if (pair.first == "size") {
m_fontSize = get_value<float>(pair.second);
return;
}
}
}
示例14: ParseCommon
void DistanceFieldFont::ParseCommon(const StringRange &line)
{
std::stringstream ss(line.ToString());
std::string token;
while (ss >> token != 0) {
std::pair<std::string, std::string> pair;
split_token(token, pair);
if (pair.first == "scaleW")
m_sheetSize.x = get_value<float>(pair.second);
else if (pair.first == "scaleH")
m_sheetSize.y = get_value<float>(pair.second);
}
}
示例15: getValueKind
Registry::ValueKind Registry::getValueKind(StringRange valueName) const {
assert("Empty Registry" && *this);
ValueKind kind;
const LONG result = RegQueryValueExW(_handle, valueName.c_str(), nullptr, reinterpret_cast<LPDWORD>(&kind), nullptr, nullptr);
if (result == ERROR_FILE_NOT_FOUND) {
return ValueKind::notFound;
} else {
checkResult(result);
if (!ValueKind::_validate(kind)) {
return ValueKind::unknown;
}
}
return kind;
}