本文整理汇总了C++中ustring::length方法的典型用法代码示例。如果您正苦于以下问题:C++ ustring::length方法的具体用法?C++ ustring::length怎么用?C++ ustring::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ustring
的用法示例。
在下文中一共展示了ustring::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
void DataValue::parse(const ustring &text, DataType type, void *value) {
switch(type) {
case data_int:
case data_combo:
case data_flags:
case data_comboEx:
*(int *)value = atoi(text.c_str());
break;
case data_str:
if(text[0] == '"')
((ustring*)value)->assign(text, 1, text.length() - 2);
else if(text[0] == '#')
parseStrList(text, value);
else
*(ustring*)value = text;
break;
case data_stock:
case data_element:
if(text[0] == '"')
((ustring*)value)->assign(text, 1, text.length() - 2);
else
*(ustring*)value = text;
break;
case data_real:
*(double *)value = atof(text.c_str());
break;
case data_data: {
int i;
static const int dtypes[] = { data_int, data_str, data_real };
for(int t = 0; t < 3; t++)
if(strncmp(text.c_str(), dataNames[dtypes[t]], i = strlen(dataNames[dtypes[t]])) == 0) {
ustring s = ustring(text, i+1, text.length() - i - 2);
switch(t) {
case 0: *(TData*)value = atoi(s.c_str()); break;
case 1: *(TData*)value = s; break;
case 2: *(TData*)value = atof(s.c_str()); break;
}
}
break;
}
case data_list:
parseStrList(text, value);
break;
case data_pixbuf:
parsePixbuf(text, value);
break;
case data_array:
parseArray(text, value);
break;
case data_color:
((TypeColor*)value)->set(text);
break;
case data_font:
parseFont(text, value);
break;
default:
;
}
}
示例2: Import
void CDate::Import(ustring a)
{
do
{
int dem = 0;
int dk = 0;
int j = 0;
char** temp = new char*[3]; //Tạo con trỏ hai chiều kiểu char
for(int i = 0; i < 3; i++) //Vòng lặp khởi tạo vùng nhớ cho biến
temp[i] = new char[a.length()];
for(int i = 0; i < a.length(); i++) //Vòng lặp chạy từ cuối chuỗi
{
if(a[i] >= '0' && a[i] <= '9') //Nếu gặp phần tử là số thì thêm vào biến tạm thứ dem.
{
temp[dem][j] = a[i];
j++;
}
else //Nếu gặp thì tăng dem lên 1 để chuyển biến tạm và j = 0 để trở về vị trí ban đầu của biến tạm mới
{
dem++;
j = 0;
}
}
this->m_day = atoi(temp[0]); //Chuyển giá trị trong chuỗi thành kiểu nguyên và gán cho thuộc tính của con trỏ this
this->m_month = atoi(temp[1]); //Tương tự
this->m_year = atoi(temp[2]); //Tương tự
} while(this->m_year < 0 || this->m_month < 0 || this->m_month > 12 || (CheckYear(this->m_year) == 0 && this->m_day > SizeMonth[this->m_month - 1] || this->m_day < 0) || (CheckYear(this->m_year) == 1 && this->m_day > _SizeMonth[this->m_month - 1] || this->m_day < 0)); //Điều kiện dùng của vòng lặp nhập thời gian
}
示例3: send_line
void WindowsOutpost::send_line(const ustring & command)
// Sends "command" to the windows outpost.
{
int result = 0;
if (connected) {
// Discard any previous reply.
char buf[1024];
#ifdef WIN32
if (recv(sock, buf, sizeof(buf), 0)) ;
if (send(sock, command.c_str(), command.length(), 0)) ;
result = send(sock, "\n", 1, 0);
#else
if (read(sock, buf, sizeof(buf))) ;
if (write(sock, command.c_str(), command.length())) ;
result = write(sock, "\n", 1);
#endif
// Give some time to allow the reply to come back.
g_usleep(1000000);
}
if (result < 0) {
connected = false;
#ifndef WIN32
perror(NULL);
#endif
log(_("Error sending data"));
clear();
}
}
示例4: searchwords_find_fast
void Highlight::searchwords_find_fast(GtkTextBuffer * textbuffer, GtkTextIter * beginbound, GtkTextIter * endbound, const ustring & searchword, bool casesensitive, vector < GtkTextIter > &wordstart, vector < GtkTextIter > &wordend)
// Searches for words to highlight. For simple highligthing.
// Is much faster than the slow routine, see there fore more information.
{
// Variable.
GtkTextIter begin;
GtkTextIter end;
// Extract the line.
ustring line = gtk_text_buffer_get_slice(textbuffer, beginbound, endbound, false);
// Deal with case sensitivity.
ustring case_considerate_search_word(searchword);
if (!casesensitive)
case_considerate_search_word = case_considerate_search_word.casefold();
// Go through the line looking for matches.
for (unsigned int i = 0; i < line.length(); i++) {
if (interrupt_thread)
continue;
ustring compareline(line.substr(i, searchword.length()));
// Deal with case sensitivity.
if (!casesensitive)
compareline = compareline.casefold();
// Now compare.
if (case_considerate_search_word == compareline) {
// Get the iterators in the textbuffer that belong to this possible match.
begin = *beginbound;
gtk_text_iter_forward_chars(&begin, i);
end = begin;
gtk_text_iter_forward_chars(&end, searchword.length());
// Add the boundaries of the word to highlight.
wordstart.push_back(begin);
wordend.push_back(end);
}
}
}
示例5: Draw
void TextSupervisor::Draw(const ustring &text, const TextStyle &style)
{
if(text.empty()) {
IF_PRINT_WARNING(VIDEO_DEBUG) << "empty string was passed to function" << std::endl;
return;
}
if(IsFontValid(style.font) == false) {
IF_PRINT_WARNING(VIDEO_DEBUG) << "failed because font was invalid: " << style.font << std::endl;
return;
}
FontProperties *fp = _font_map[style.font];
VideoManager->PushState();
// Break the string into lines and render the shadow and text for each line
uint16 buffer[2048];
const uint16 NEWLINE = '\n';
size_t last_line = 0;
do {
// Find the next new line character in the string and save the line
size_t next_line;
for(next_line = last_line; next_line < text.length(); next_line++) {
if(text[next_line] == NEWLINE)
break;
buffer[next_line - last_line] = text[next_line];
}
buffer[next_line - last_line] = 0;
last_line = next_line + 1;
// If this line is empty, skip on to the next one
if(buffer[0] == 0) {
VideoManager->MoveRelative(0, -fp->line_skip * VideoManager->_current_context.coordinate_system.GetVerticalDirection());
continue;
}
// Save the draw cursor position before drawing this text
VideoManager->PushMatrix();
// If text shadows are enabled, draw the shadow first
if(style.shadow_style != VIDEO_TEXT_SHADOW_NONE) {
VideoManager->PushMatrix();
const float dx = VideoManager->_current_context.coordinate_system.GetHorizontalDirection() * style.shadow_offset_x;
const float dy = VideoManager->_current_context.coordinate_system.GetVerticalDirection() * style.shadow_offset_y;
VideoManager->MoveRelative(dx, dy);
_DrawTextHelper(buffer, fp, _GetTextShadowColor(style));
VideoManager->PopMatrix();
}
// Now draw the text itself, restore the position of the draw cursor, and move the draw cursor one line down
_DrawTextHelper(buffer, fp, style.color);
VideoManager->PopMatrix();
VideoManager->MoveRelative(0, -fp->line_skip * VideoManager->_current_context.coordinate_system.GetVerticalDirection());
} while(last_line < text.length());
VideoManager->PopState();
} // void TextSupervisor::Draw(const ustring& text)
示例6: replace_text
bool replace_text(ustring & line, const ustring & look_for, const ustring & replace_with)
// Replaces some text. Returns true if any replacement was done.
{
bool replacements_done = false;
size_t offposition = line.find (look_for);
while (offposition != string::npos) {
line.replace (offposition, look_for.length (), replace_with);
offposition = line.find (look_for, offposition + replace_with.length ());
replacements_done = true;
}
return replacements_done;
}
示例7: loadKeys
bool PubAddr::loadKeys(ustring Skey, ustring Ekey, int nonce, int extra)
{
std::unique_lock<std::shared_timed_mutex> mlock(this->mutex_);
this->extra_bytes = extra;
this->nonce_trials = nonce;
this->pubEncryptionKey.clear();
this->pubSigningKey.clear();
int length = Ekey.length();
if (length == 64)
{
this->pubEncryptionKey += 0x04;
this->pubEncryptionKey += Ekey;
}
else if (length == 65)
{
if (Ekey.c_str()[0] != 0x04)
{
mlock.unlock();
return false;
}
this->pubEncryptionKey += Ekey;
}
length = Skey.length();
if (length == 64)
{
this->pubSigningKey += 0x04;
this->pubSigningKey += Skey;
}
else if (length == 65)
{
if (Skey.c_str()[0] != 0x04)
{
mlock.unlock();
return false;
}
this->pubSigningKey += Skey;
}
this->empty = false;
mlock.unlock();
return true;
}
示例8: replace_text_between
bool replace_text_between(ustring & line, const ustring & start, const ustring & end, const ustring & replacement)
// Replaces text that starts with "start" and ends with "end" with "replacement".
// Returns true if replacement was done.
{
bool replacements_done = false;
size_t beginpos = line.find(start);
size_t endpos = line.find(end);
while ((beginpos != string::npos) && (endpos != string::npos) && (endpos > beginpos)) {
line.replace(beginpos, endpos - beginpos + end.length(), replacement);
beginpos = line.find(start, beginpos + replacement.length());
endpos = line.find(end, beginpos + replacement.length());
replacements_done = true;
}
return replacements_done;
}
示例9: strtol
int strtol(long &value, ustring str, long &value2, ustring str2, int base)
{
const char *nptr = str.c_str();
const char *nptr2 = str.c_str();
char *eptr, *eptr2;
value = ::strtol(nptr, &eptr, base);
value2 = ::strtol(nptr2, &eptr2, base);
if ( (nptr==eptr) || (nptr2==eptr2) )
return -1;
else if ( (eptr<(char*)nptr+str.length()) && (eptr2<(char*)nptr2+str2.length()) )
return 0;
else
return 1;
}
示例10: analyseWord
ustringArrayT analyseWord (ustring str) {
typedef bool (*_TrivialPointerToFunctions_) (ustring);
ustringArrayT res(3);
_TrivialPointerToFunctions_ testFuncs[3] =
{ isConsonant, isVowel, isConsonant };
// First part: Consonant 1
// Second part: Vowel
// Third part: Consonant 2
for (int part = 0; part < 3; part++) {
res[part] = "";
// This is safe due to short-circuit logic
while (str.length () > 0 && testFuncs[part] (_(str[0]))) {
res[part] += _(str[0]);
str.replace (0, 1, "");
}
}
// Special case: "qu" and "gi" are considered consonants
if (analyseWordCheckSpecialConsonants (res, "qu") ||
analyseWordCheckSpecialConsonants (res, "gi")) {
res[0] += _(res[1][0]);
res[1] = res[1].replace (0, 1, "");
}
return res;
}
示例11: GetStringWidth
float CFont::GetStringWidth( const ustring& text, bool offsetFirstCharacter /*= false*/ )
{
float totalW = 0;
uchar lastChar = 0;
for ( int i = 0; i < text.length(); ++i )
{
uchar c = text[i];
auto descIt = m_chars.find(c);
if ( descIt == m_chars.end() )
{
descIt = m_chars.find( -1 );
}
auto & desc = descIt->second;
if (i != 0 || offsetFirstCharacter)
{
totalW += desc.offset.x;
}
totalW += desc.xAdvance;
auto kernIt = m_kernings.find( std::make_pair( lastChar, c ) );
if ( kernIt != m_kernings.end() )
{
totalW += kernIt->second;
}
lastChar = c;
}
return totalW;
}
示例12: string_reverse
ustring string_reverse(const ustring & s)
{
ustring returnvalue;
for (int i = s.length() - 1; i >= 0; i--)
returnvalue.append(s.substr(i, 1));
return returnvalue;
}
示例13:
// Heavy lifting of OSL regex operations.
OSL_SHADEOP int
osl_regex_impl2 (OSL::ShadingContext *ctx, ustring subject_,
int *results, int nresults, ustring pattern,
int fullmatch)
{
const std::string &subject (subject_.string());
boost::match_results<std::string::const_iterator> mresults;
const boost::regex ®ex (ctx->find_regex (pattern));
if (nresults > 0) {
std::string::const_iterator start = subject.begin();
int res = fullmatch ? boost::regex_match (subject, mresults, regex)
: boost::regex_search (subject, mresults, regex);
int *m = (int *)results;
for (int r = 0; r < nresults; ++r) {
if (r/2 < (int)mresults.size()) {
if ((r & 1) == 0)
m[r] = mresults[r/2].first - start;
else
m[r] = mresults[r/2].second - start;
} else {
m[r] = pattern.length();
}
}
return res;
} else {
return fullmatch ? boost::regex_match (subject, regex)
: boost::regex_search (subject, regex);
}
}
示例14: DASSERT
int
Dictionary::get_document_index (ustring dictionaryname)
{
DocMap::iterator dm = m_document_map.find(dictionaryname);
int dindex;
if (dm == m_document_map.end()) {
dindex = m_documents.size();
m_document_map[dictionaryname] = dindex;
pugi::xml_document *doc = new pugi::xml_document;
m_documents.push_back (doc);
pugi::xml_parse_result parse_result;
if (boost::ends_with (dictionaryname.string(), ".xml")) {
// xml file -- read it
parse_result = doc->load_file (dictionaryname.c_str());
} else {
// load xml directly from the string
parse_result = doc->load_buffer (dictionaryname.c_str(),
dictionaryname.length());
}
if (! parse_result) {
m_context->error ("XML parsed with errors: %s, at offset %d",
parse_result.description(),
parse_result.offset);
m_document_map[dictionaryname] = -1;
return -1;
}
} else {
dindex = dm->second;
}
DASSERT (dindex < (int)m_documents.size());
return dindex;
}
示例15: lowerCase
ustring lowerCase(const ustring & s)
{
// Make a lowercase copy of s
string lower(s);
for (size_t i = 0; i < s.length(); ++i)
lower[i] = tolower(lower[i]);
return lower;
}