本文整理汇总了C++中StringView::getPtr方法的典型用法代码示例。如果您正苦于以下问题:C++ StringView::getPtr方法的具体用法?C++ StringView::getPtr怎么用?C++ StringView::getPtr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringView
的用法示例。
在下文中一共展示了StringView::getPtr方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: urlEncode
// https://secure.wikimedia.org/wikipedia/en/wiki/URL_encoding
void urlEncode(char* _out, uint32_t _max, const StringView& _str)
{
_max--; // need space for zero terminator
const char* str = _str.getPtr();
const char* term = _str.getTerm();
uint32_t ii = 0;
for (char ch = *str++
; str <= term && ii < _max
; ch = *str++
)
{
if (isAlphaNum(ch)
|| ch == '-'
|| ch == '_'
|| ch == '.'
|| ch == '~')
{
_out[ii++] = ch;
}
else if (ii+3 < _max)
{
_out[ii++] = '%';
_out[ii++] = toHex(ch>>4);
_out[ii++] = toHex(ch);
}
}
示例2: get
const char* Settings::get(const StringView& _name) const
{
ini_t* ini = INI_T(m_ini);
FilePath uri(_name);
const StringView path(strTrim(uri.getPath(), "/") );
const StringView& fileName(uri.getFileName() );
int32_t section = INI_GLOBAL_SECTION;
if (!path.isEmpty() )
{
section = ini_find_section(ini, path.getPtr(), path.getLength() );
if (INI_NOT_FOUND == section)
{
section = INI_GLOBAL_SECTION;
}
}
int32_t property = ini_find_property(ini, section, fileName.getPtr(), fileName.getLength() );
if (INI_NOT_FOUND == property)
{
return NULL;
}
return ini_property_value(ini, section, property);
}
示例3: remove
void Settings::remove(const StringView& _name) const
{
ini_t* ini = INI_T(m_ini);
FilePath uri(_name);
const StringView path = strTrim(uri.getPath(), "/");
const StringView& fileName = uri.getFileName();
int32_t section = INI_GLOBAL_SECTION;
if (!path.isEmpty() )
{
section = ini_find_section(ini, path.getPtr(), path.getLength() );
if (INI_NOT_FOUND == section)
{
section = INI_GLOBAL_SECTION;
}
}
int32_t property = ini_find_property(ini, section, fileName.getPtr(), fileName.getLength() );
if (INI_NOT_FOUND == property)
{
return;
}
ini_property_remove(ini, section, property);
if (INI_GLOBAL_SECTION != section
&& 0 == ini_property_count(ini, section) )
{
ini_section_remove(ini, section);
}
}
示例4: set
void Settings::set(const StringView& _name, const StringView& _value)
{
ini_t* ini = INI_T(m_ini);
FilePath uri(_name);
const StringView path(strTrim(uri.getPath(), "/") );
const StringView& fileName(uri.getFileName() );
int32_t section = INI_GLOBAL_SECTION;
if (!path.isEmpty() )
{
section = ini_find_section(ini, path.getPtr(), path.getLength() );
if (INI_NOT_FOUND == section)
{
section = ini_section_add(ini, path.getPtr(), path.getLength() );
}
}
int32_t property = ini_find_property(ini, section, fileName.getPtr(), fileName.getLength() );
if (INI_NOT_FOUND == property)
{
ini_property_add(
ini
, section
, fileName.getPtr()
, fileName.getLength()
, _value.getPtr()
, _value.getLength()
);
}
else
{
ini_property_value_set(
ini
, section
, property
, _value.getPtr()
, _value.getLength()
);
}
}
示例5: parse
bool UrlView::parse(const StringView& _url)
{
clear();
const char* start = _url.getPtr();
const char* term = _url.getTerm();
const char* schemeEnd = strFind(StringView(start, term), "://");
const char* hostStart = NULL != schemeEnd ? schemeEnd+3 : start;
const char* pathStart = strFind(StringView(hostStart, term), '/');
if (NULL == schemeEnd
&& NULL == pathStart)
{
return false;
}
if (NULL != schemeEnd
&& (NULL == pathStart || pathStart > schemeEnd) )
{
StringView scheme(start, schemeEnd);
if (!isAlpha(scheme) )
{
return false;
}
m_tokens[Scheme].set(scheme);
}
if (NULL != pathStart)
{
const char* queryStart = strFind(StringView(pathStart, term), '?');
const char* fragmentStart = strFind(StringView(pathStart, term), '#');
if (NULL != fragmentStart
&& fragmentStart < queryStart)
{
return false;
}
m_tokens[Path].set(pathStart
, NULL != queryStart ? queryStart
: NULL != fragmentStart ? fragmentStart
: term
);
if (NULL != queryStart)
{
m_tokens[Query].set(queryStart+1
, NULL != fragmentStart ? fragmentStart
: term
);
}
if (NULL != fragmentStart)
{
m_tokens[Fragment].set(fragmentStart+1, term);
}
term = pathStart;
}
const char* userPassEnd = strFind(StringView(hostStart, term), '@');
const char* userPassStart = NULL != userPassEnd ? hostStart : NULL;
hostStart = NULL != userPassEnd ? userPassEnd+1 : hostStart;
const char* portStart = strFind(StringView(hostStart, term), ':');
m_tokens[Host].set(hostStart, NULL != portStart ? portStart : term);
if (NULL != portStart)
{
m_tokens[Port].set(portStart+1, term);
}
if (NULL != userPassStart)
{
const char* passStart = strFind(StringView(userPassStart, userPassEnd), ':');
m_tokens[UserName].set(userPassStart
, NULL != passStart ? passStart
: userPassEnd
);
if (NULL != passStart)
{
m_tokens[Password].set(passStart+1, userPassEnd);
}
}
return true;
}