本文整理匯總了C++中string_t::size方法的典型用法代碼示例。如果您正苦於以下問題:C++ string_t::size方法的具體用法?C++ string_t::size怎麽用?C++ string_t::size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類string_t
的用法示例。
在下文中一共展示了string_t::size方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: Replace
//---------------------------------------------------------------------------
void WordMacros::Replace(const string_t& text, const string_t& repl)
{
// обходим проблему текста длинее 255 символов
const size_t MAX_REPL_LEN = 200;
if (repl.size() > MAX_REPL_LEN)
{
string_t newText;
std::vector<string_t> rs;
for (size_t i = 0; i < repl.size(); i+= MAX_REPL_LEN)
{
newText += text + aux::itow(rs.size());
rs.push_back(repl.subString(i, MAX_REPL_LEN));
}
Replace(text, newText);
for (size_t i = 0; i < rs.size(); ++i)
Replace(text + aux::itow(i), rs[i]);
return;
}
m_Macros += "With Selection.Find \n";
m_Macros += " .ClearFormatting \n";
m_Macros += " .Replacement.ClearFormatting \n";
m_Macros += " .Text = \"" + text +"\" \n";
m_Macros += " .Replacement.Text = \"" + repl +"\" \n";
m_Macros += " .Execute Replace:=wdReplaceAll \n";
m_Macros += "End With \n";
IsLarge();
}
示例2: 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);
}
示例3: 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).
// *###x###*
if (str.size() >= 3 + 1 + 3)
{
size_t pos = str.find_first_of(L"xX\u00D7"); // multiplication sign
if (pos != str.npos)
{
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() >= 3 + 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;
}
示例4: dirname
string_t dirname(string_t source)
{
if (source.size() <= 1) //Make sure it's possible to check the last character.
{
return source;
}
if (*(source.rbegin() + 1) == '/') //Remove trailing slash if it exists.
{
source = source.substr(0, source.size() - 1);
}
source.erase(std::find(source.rbegin(), source.rend(), '/').base(), source.end());
return source;
}
示例5: 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)
);
}
示例6: 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();
}
示例7: check
inline void check(in_t::ptr_t const &) const {
for(typeof(list._ptr()) lptr = list; lptr; ++lptr) {
name_t const &name = lptr.val();
// #dir "/mod_" #name ".so\0"
if(module_info_t::lookup(name)) return;
string_t fname_z = string_t::ctor_t(dir.size() + 5 + name.size() + 4)
(dir)(CSTR("/mod_"))(name)(CSTR(".so\0"))
;
try {
module_load(fname_z.ptr());
}
catch(string_t const &ex) {
config::error(name.ptr, ex.ptr());
}
module_info_t *module_info = module_info_t::lookup(name);
if(!module_info)
config::error(name.ptr, "not a phantom module loaded");
if(!*module_info)
config::error(name.ptr, "illegal module version");
}
}
示例8: to_str_date
//---------------------------------------------------------------------------
string_t r::to_str_date(string_t sqlDate, string_t suffix /* = L"" */)
{
static string_t mounthNames[12]={ "¤нвар¤", "феврал¤", "марта", "апрел¤", "ма¤", "июн¤", "июл¤", "августа", "сент¤бр¤", "окт¤бр¤", "но¤бр¤", "декабр¤"};
string_t res = "";
try
{
// число
res += sqlDate.subString(8,2);
if (res.size() == 1)
res = "0" + res;
res += " ";
// мес¤ц
int mNum = (sqlDate.subString(5, 2).toInt()-1) % 12;
if (mNum < 0)
return "<невалидна¤ дата!>";
res += mounthNames[mNum] + " ";
// год
res += sqlDate.subString(0,4);
if (suffix.size())
res += L" " + suffix;
}
catch(...)
{
return "<невалидна¤ дата!>";
}
return res;
}
示例9: 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();
}
示例10: split_string
void split_string(string_t& source, const string_t& delim, std::list<string_t>& ret)
{
ret.clear();
if (delim.empty() || source.empty())
{
ret.push_back(source);
return ;
}
size_t last = 0;
size_t index = source.find(delim, last);
while (index!=std::string::npos)
{
ret.push_back(source.substr(last, index - last));
last = index + delim.size();
index = source.find(delim, last);
}
if(index - last > 0)
{
ret.push_back(source.substr(last, index - last));
}
}
示例11:
// 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 ));
}
}
示例12: for
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);
}
}}
}
示例13: prepare
void statement::prepare()
{
try
{
typedef meta::if_<sizeof(char_t) == sizeof(utf8_char), char const*, void const*>::type tail_type;
char_t const* tail;
string_t const sql = q_.sql();
s_.check_error(
aux::select(::sqlite3_prepare, ::sqlite3_prepare16)(s_.impl_, sql.c_str(),
static_cast<int>(sql.size() * sizeof(char_t)),
&impl_, reinterpret_cast<tail_type*>(&tail)) );
if ( tail && *tail )
{
throw multi_stmt_not_supported();
}
// bind into binders
std::accumulate(q_.intos().begin(), q_.intos().end(), 0, bind(*this));
// bind use binders
std::accumulate(q_.uses().begin(), q_.uses().end(), 1, bind(*this));
}
catch(std::exception const&)
{
// statement stays not prepared
finalize(false);
throw;
}
}
示例14: 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);
}
示例15: mime_type_need_charset
// ugly function #1
static bool mime_type_need_charset(string_t const &mtype) {
char const *p = mtype.ptr();
return (
mtype.size() >= 5 &&
p[0] == 't' && p[1] == 'e' && p[2] == 'x' && p[3] == 't' && p[4] == '/'
);
}