本文整理汇总了C++中ConfigSection::find_entry方法的典型用法代码示例。如果您正苦于以下问题:C++ ConfigSection::find_entry方法的具体用法?C++ ConfigSection::find_entry怎么用?C++ ConfigSection::find_entry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigSection
的用法示例。
在下文中一共展示了ConfigSection::find_entry方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_allocated
bool Config::get_allocated(const char* section, const char* key, char** ret, unsigned int& retsize) {
retsize = 0;
ConfigSection* cs = find_section(section);
if (!cs) {
errcode = CONF_ERR_SECTION;
return false;
}
ConfigEntry* ce = cs->find_entry(key);
if (!ce) {
errcode = CONF_ERR_KEY;
return false;
}
char* value = ce->value;
retsize = ce->valuelen;
*ret = new char[retsize + 1];
strncpy(*ret, value, retsize);
// terminate, since ce->valuelen does not contain terminating char
char* p = *ret;
p[retsize] = '\0';
return true;
}
示例2: get
bool Config::get(const char* section, const char* key, char* ret, unsigned int size) {
ConfigSection* cs = find_section(section);
if (!cs) {
errcode = CONF_ERR_SECTION;
return false;
}
ConfigEntry* ce = cs->find_entry(key);
if (!ce) {
errcode = CONF_ERR_KEY;
return false;
}
char* value = ce->value;
strncpy(ret, value, size);
// again, strncpy does not terminate string if size is less that actual
if(ce->valuelen > size)
ret[size-1] = '\0';
return true;
}
示例3: get_localized
bool Config::get_localized(const char* section, const char* key, char* ret, unsigned int size) {
char* lang = getenv("LANG");
// fallback
if (!lang)
return get(section, key, ret, size);
// do not use default locales
if (lang[0] == 'C' || (strncmp(lang, "en_US", 5) == 0))
return get(section, key, ret, size);
ConfigSection* cs = find_section(section);
if (!cs) {
errcode = CONF_ERR_SECTION;
return false;
}
char key_buf[128];
/*
* Config class can accept Name[xxx] names as
* keys, so we use it here; first construct
* a key name, and try to find it
*/
snprintf(key_buf, sizeof(key_buf), "%s[%s]", key, lang);
bool found = false;
// first try to find it with full data
ConfigEntry* ce = cs->find_entry(key_buf);
if (ce)
found = true;
else {
/*
* We will try in this order:
* 1. [email protected]
* 2. [email protected]
* 3. lc_CC (language code with country code)
* 4. lc
*/
char delim[] = {'.', '@', '_'};
char* p;
char* code;
for (int i = 0; i < 3; i++) {
p = strchr(lang, delim[i]);
if (p != NULL) {
int sz = p - lang;
code = new char[sz+1];
strncpy(code, lang, sz);
// damint strncpy does not add this
code[sz] = '\0';
snprintf(key_buf, sizeof(key_buf), "%s[%s]", key, code);
delete [] code;
ce = cs->find_entry(key_buf);
if (ce) {
found = true;
break;
}
}
}
}
if (found) {
char* value = ce->value;
strncpy(ret, value, size);
ret[size-1] = '\0';
return true;
} else
errcode = CONF_ERR_KEY;
return false;
}
示例4: key_exist
bool Config::key_exist(const char* section, const char* key) {
ConfigSection* cs = find_section(section);
if(!cs)
return false;
return (cs->find_entry(key) != NULL);
}