本文整理匯總了C++中string_t類的典型用法代碼示例。如果您正苦於以下問題:C++ string_t類的具體用法?C++ string_t怎麽用?C++ string_t使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了string_t類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: assert
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;
}
示例2: IsDashCharacter
bool Parser::IsDashCharacter(const string_t& str) {
if (str.size() != 1)
return false;
auto result = std::find(kDashes.begin(), kDashes.end(), str.front());
return result != kDashes.end();
}
示例3: WBUFB
CServerMessagePacket::CServerMessagePacket(const string_t message, int8 language, int32 timestamp, int32 message_offset)
{
this->type = 0x4D;
this->size = 0x0E;
WBUFB(data, (0x04) ) = message_offset == 0 ? 1 : 2;
WBUFB(data, (0x05) ) = 1;
WBUFB(data, (0x06) ) = 1;
WBUFB(data, (0x07) ) = language;
WBUFL(data, (0x08) ) = timestamp == 0 ? time(0) : timestamp;
WBUFL(data, (0x0C) ) = 0; // Message Length.. (Total)
WBUFL(data, (0x10) ) = 0; // Message Offset..
WBUFL(data, (0x14) ) = 0; // Message Length..
// Ensure we have a message and the requested offset is not outside of the bounds..
if (message.length() > 0 && message.length() > message_offset)
{
int32 msgLength = message.length();
int32 sndLength = (msgLength - message_offset) > 236 ? 236 : (msgLength - message_offset);
WBUFL(data, (0x0C) ) = message.length(); // Message Length.. (Total)
WBUFL(data, (0x10) ) = message_offset; // Message Offset..
WBUFL(data, (0x14) ) = sndLength; // Message Length..
memcpy((data + (0x18)) , message.c_str() + message_offset, sndLength);
int32 textSize = sndLength + sndLength % 2;
this->size = ((((0x14 + textSize) + 4) >> 1) & 0xFE);
}
示例4: CamelCase
// From CamelCase to snake_case
std::string CamelCase(const string_t & name)
{
// Replace '_' + a lowercase letter with an upper case letter
string_t str;
str.reserve(name.size());
for (size_t i = 0; i < name.size(); ++i)
{
if (i == 0 || name[i] == puzT('_'))
{
if (i > 0)
++i;
if (i < name.size())
{
#if PUZ_UNICODE
if (::iswlower(name[i]))
str.push_back(::towupper(name[i]));
#else // ! PUZ_UNICODE
if (::islower(name[i]))
str.push_back(::toupper(name[i]));
#endif // PUZ_UNICODE/! PUZ_UNICODE
else // Not lower case: so push both the underscore and letter
{
if (i > 0)
str.push_back(name[i-1]);
str.push_back(name[i]);
}
}
else if (i > 0) // At the end of the string: push the underscore
str.push_back(name[i-1]);
}
else // Not a hypen: push the letter
str.push_back(name[i]);
}
return encode_utf8(str);
}
示例5: MatchTypeAndEpisodePattern
bool Parser::MatchTypeAndEpisodePattern(const string_t& word, Token& token) {
size_t number_begin = FindNumberInString(word);
auto prefix = word.substr(0, number_begin);
ElementCategory category = kElementAnimeType;
KeywordOptions options;
if (keyword_manager.Find(keyword_manager.Normalize(prefix),
category, options)) {
elements_.insert(kElementAnimeType, prefix);
auto number = word.substr(number_begin);
if (MatchEpisodePatterns(number, token) ||
SetEpisodeNumber(number, token, true)) {
auto it = std::find(tokens_.begin(), tokens_.end(), token);
if (it != tokens_.end()) {
// Split token (we do this last in order to avoid invalidating our
// token reference earlier)
token.content = number;
tokens_.insert(it, Token(options.identifiable ? kIdentifier : kUnknown,
prefix, token.enclosed));
}
return true;
}
}
return false;
}
示例6: IsResolution
bool Parser::IsResolution(const string_t& str) {
// Using a regex such as "\\d{3,4}(p|(x\\d{3,4}))$" would be more elegant,
// but it's much slower (e.g. 2.4ms -> 24.9ms).
const size_t min_width_size = 3;
const size_t min_height_size = 3;
// *###x###*
if (str.size() >= min_width_size + 1 + min_height_size) {
size_t pos = str.find_first_of(L"xX\u00D7"); // multiplication sign
if (pos != str.npos &&
pos >= min_width_size &&
pos <= str.size() - (min_height_size + 1)) {
for (size_t i = 0; i < str.size(); i++)
if (i != pos && !IsNumericChar(str.at(i)))
return false;
return true;
}
// *###p
} else if (str.size() >= min_height_size + 1) {
if (str.back() == L'p' || str.back() == L'P') {
for (size_t i = 0; i < str.size() - 1; i++)
if (!IsNumericChar(str.at(i)))
return false;
return true;
}
}
return false;
}
示例7: GetDelimiters
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();
}
示例8: linking_procedure
// Creates a string of neighboring edge pixels.
inline
void
linking_procedure(string_t &string, unsigned char *binary_image, const size_t image_width, const size_t image_height, const int x_ref, const int y_ref, const double half_width, const double half_height)
{
/* Leandro A. F. Fernandes, Manuel M. Oliveira
* Real-time line detection through an improved Hough transform voting scheme
* Pattern Recognition (PR), Elsevier, 41:1, 2008, 299-314.
*
* Algorithm 5
*/
int x, y;
string.clear();
// Find and add feature pixels to the end of the string.
x = x_ref;
y = y_ref;
do
{
pixel_t &p = string.push_back();
p.x_index = x;
p.y_index = y;
p.x = x - half_width;
p.y = y - half_height;
binary_image[y*image_width+x] = 0;
}
while (next( x, y, binary_image, image_width, image_height ));
pixel_t temp;
for (size_t i=0, j=string.size()-1; i<j; ++i, --j)
{
temp = string[i];
string[i] = string[j];
string[j] = temp;
}
// Find and add feature pixels to the begin of the string.
x = x_ref;
y = y_ref;
if (next( x, y, binary_image, image_width, image_height ))
{
do
{
pixel_t &p = string.push_back();
p.x_index = x;
p.y_index = y;
p.x = x - half_width;
p.y = y - half_height;
binary_image[y*image_width+x] = 0;
}
while (next( x, y, binary_image, image_width, image_height ));
}
}
示例9: defined
virtual bool open_file
(io::read::file& file, const string_t& line,
const string_t& name, bool mode_is_binary = false) {
size_t length;
if ((line.has_chars(length))) {
#if defined(__GNUC__)
char_t chars[length + 3];
#else // defined(__GNUC__)
nadir::arrayt<char_t> a(length + 3);
char_t* chars = a.elements();
#endif // defined(__GNUC__)
if ((file.open(name.chars(), (mode_is_binary)
?(file.mode_read_binary()):(file.mode_read())))) {
if (!((length + 2) != (file.read(chars, length + 2)))) {
if (!(line.compare(chars, length))) {
if (!((cr_ != chars[length]) || (lf_ != chars[length+1]))) {
return true;
}
}
}
file.close();
}
}
return false;
}
示例10: Peek
void KeywordManager::Peek(const string_t& filename,
const TokenRange& range,
Elements& elements,
std::vector<TokenRange>& preidentified_tokens) const {
typedef std::pair<ElementCategory, std::vector<string_t>> entry_t;
static const std::vector<entry_t> entries{
{kElementAudioTerm, {L"Dual Audio"}},
{kElementVideoTerm, {L"H264", L"H.264", L"h264", L"h.264"}},
{kElementVideoResolution, {L"480p", L"720p", L"1080p"}},
{kElementSource, {L"Blu-Ray"}}
};
auto it_begin = filename.begin() + range.offset;
auto it_end = it_begin + range.size;
for (const auto& entry : entries) {
for (const auto& keyword : entry.second) {
auto it = std::search(it_begin, it_end, keyword.begin(), keyword.end());
if (it != it_end) {
auto offset = it - filename.begin();
elements.insert(entry.first, keyword);
preidentified_tokens.push_back(TokenRange(offset, keyword.size()));
}
}
}
}
示例11: 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)
);
}
示例12: exception_sys_t
file_t::file_t(char const *name, string_t const &header) :
ref_cnt(0), fd(-1), used(false), id() {
if(config::check)
return;
fd = ::open(name, O_WRONLY | O_APPEND | O_CREAT, 0644);
if(fd < 0)
throw exception_sys_t(log::error, errno, "open (%s): %m", name);
fd_guard_t guard(fd);
id = id_t(fd, used);
if(!id)
throw exception_sys_t(log::error, errno, "fstat (%s): %m", name);
if(::flock(fd, LOCK_SH | LOCK_NB) < 0)
throw exception_sys_t(log::error, errno, "flock (%s): %m", name);
if(header) {
if(::write(fd, header.ptr(), header.size()) < 0)
throw exception_sys_t(log::error, errno, "write (%s): %m", name);
}
guard.relax();
}
示例13: 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);
}
示例14: test_1_01
static void test_1_01()
{
PAN_CHAR_T hostname[1000];
const string_t hid = pan_get_hid_();
{ for(size_t i = 0; i != STLSOFT_NUM_ELEMENTS(hostname); ++i)
{
::memset(&hostname[0], 0, sizeof(hostname));
const size_t len = pantheios::getHostName(&hostname[0], i);
if(len == i)
{
// The function did not have enough space to write in, so it
// will return the length passed to it ...
XTESTS_TEST_INTEGER_EQUAL(i, len);
// ... and will not have written anything to the file
XTESTS_TEST_STRING_EQUAL(PANTHEIOS_LITERAL_STRING(""), hostname);
}
else
{
// The function had enough space, so it will return the length
// of the intended hostname ...
XTESTS_TEST_INTEGER_EQUAL(hid.size(), len);
// ... and will have written the hostname
XTESTS_TEST_STRING_EQUAL(hid, hostname);
}
}}
}
示例15: containsKeyword
bool containsKeyword (string_t keyword, value_t& value)
{
typename Entry::childen_t::iterator current;
typename Entry::childen_t::iterator next;
current = mRoot.mChildren.find (std::tolower (*keyword.begin(), mLocale));
if (current == mRoot.mChildren.end())
return false;
else if (current->second.mKeyword.size() && Misc::StringUtils::ciEqual(current->second.mKeyword, keyword))
{
value = current->second.mValue;
return true;
}
for (Point i = ++keyword.begin(); i != keyword.end(); ++i)
{
next = current->second.mChildren.find(std::tolower (*i, mLocale));
if (next == current->second.mChildren.end())
return false;
if (Misc::StringUtils::ciEqual(next->second.mKeyword, keyword))
{
value = next->second.mValue;
return true;
}
current = next;
}
return false;
}