本文整理汇总了C++中unc_text类的典型用法代码示例。如果您正苦于以下问题:C++ unc_text类的具体用法?C++ unc_text怎么用?C++ unc_text使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了unc_text类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compare
int unc_text::compare(const unc_text& ref1, const unc_text& ref2, int len)
{
int idx, len1, len2;
len1 = ref1.size();
len2 = ref2.size();
if (len > 0)
{
for (idx = 0; (idx < len1) && (idx < len2) && (idx < len); idx++)
{
if (ref1.m_chars[idx] != ref2.m_chars[idx])
{
return(ref1.m_chars[idx] - ref2.m_chars[idx]);
}
}
if (idx == len)
{
return 0;
}
return(len1 - len2);
}
for (idx = 0; (idx < len1) && (idx < len2); idx++)
{
if (ref1.m_chars[idx] != ref2.m_chars[idx])
{
return(ref1.m_chars[idx] - ref2.m_chars[idx]);
}
}
return (len1 - len2);
}
示例2: startswith
bool unc_text::startswith(const unc_text &text, size_t idx) const
{
size_t si = 0;
const auto orig_idx = idx;
for ( ; idx < size() && si < text.size(); idx++, si++)
{
if (text.m_chars[si] != m_chars[idx])
{
return(false);
}
}
return(idx != orig_idx && (si == text.size()));
}
示例3: next_up
static int next_up(const unc_text& text, int idx, unc_text& tag)
{
int offs = 0;
while ((idx < text.size()) && unc_isspace(text[idx]))
{
idx++;
offs++;
}
if (text.startswith(tag, idx))
{
return(offs);
}
return(-1);
}
示例4: startswith
bool unc_text::startswith(const unc_text& text, int idx) const
{
bool match = false;
int si = 0;
while ((idx < size()) && (si < text.size()))
{
if (text.m_chars[si] != m_chars[idx])
{
return false;
}
idx++;
si++;
match = true;
}
return(match && (si == text.size()));
}
示例5: add_text
static void add_text(const unc_text& text)
{
for (int idx = 0; idx < text.size(); idx++)
{
add_char(text[idx]);
}
}
示例6: unc_tolower
int unc_text::compare(const unc_text &ref1, const unc_text &ref2, size_t len, bool tcare)
{
const size_t len1 = ref1.size();
const size_t len2 = ref2.size();
const auto max_idx = std::min({ len, len1, len2 });
size_t idx = 0;
for ( ; idx < max_idx; idx++)
{
// exactly the same character ?
if (ref1.m_chars[idx] == ref2.m_chars[idx])
{
continue;
}
int diff; // Issue #2091
if (tcare)
{
diff = ref1.m_chars[idx] - ref2.m_chars[idx];
}
else
{
diff = unc_tolower(ref1.m_chars[idx]) - unc_tolower(ref2.m_chars[idx]);
}
if (diff == 0)
{
/*
* if we're comparing the same character but in different case
* we want to favor lower case before upper case (e.g. a before A)
* so the order is the reverse of ASCII order (we negate).
*/
return(-(ref1.m_chars[idx] - ref2.m_chars[idx]));
}
// return the case-insensitive diff to sort alphabetically
return(diff);
}
if (idx == len)
{
return(0);
}
// underflow save: return(len1 - len2);
return((len1 > len2) ? (len1 - len2) : -static_cast<int>(len2 - len1));
} // unc_text::compare
示例7: cmt_parse_lead
/**
* Checks for and updates the lead chars.
*
* @param line the comment line
* @return 0=not present, >0=number of chars that are part of the lead
*/
static int cmt_parse_lead(const unc_text& line, int is_last)
{
int len = 0;
while ((len < 32) && (len < line.size()))
{
if ((len > 0) && (line[len] == '/'))
{
/* ignore combined comments */
int tmp = len + 1;
while ((tmp < line.size()) && unc_isspace(line[tmp]))
{
tmp++;
}
if ((tmp < line.size()) && (line[tmp] == '/'))
{
return 1;
}
break;
}
else if (strchr("*|\\#+", line[len]) == NULL)
{
break;
}
len++;
}
if (len > 30)
{
return 1;
}
if ((len > 0) && ((len >= line.size()) || unc_isspace(line[len])))
{
return len;
}
if ((len == 1) && (line[0] == '*'))
{
return len;
}
if (is_last && (len > 0))
{
return len;
}
return 0;
}
示例8: next_word_exceeds_limit
/**
* Count the number of characters to the end of the next chunk of text.
* If it exceeds the limit, return true.
*/
static bool next_word_exceeds_limit(const unc_text& text, int idx)
{
int length = 0;
/* Count any whitespace */
while ((idx < text.size()) && unc_isspace(text[idx]))
{
idx++;
length++;
}
/* Count non-whitespace */
while ((idx < text.size()) && !unc_isspace(text[idx]))
{
idx++;
length++;
}
return((cpd.column + length - 1) > cpd.settings[UO_cmt_width].n);
}
示例9: generate_if_conditional_as_text
/**
* This renders the #if condition to a string buffer.
*/
static void generate_if_conditional_as_text(unc_text& dst, chunk_t *ifdef)
{
chunk_t *pc;
int column = -1;
dst.clear();
for (pc = ifdef; pc != NULL; pc = chunk_get_next(pc))
{
if (column == -1)
{
column = pc->column;
}
if ((pc->type == CT_NEWLINE) ||
(pc->type == CT_COMMENT_MULTI) ||
(pc->type == CT_COMMENT_CPP))
{
break;
}
else if (pc->type == CT_NL_CONT)
{
dst += ' ';
column = -1;
}
else if ((pc->type == CT_COMMENT) ||
(pc->type == CT_COMMENT_EMBED))
{
}
else // if (pc->type == CT_JUNK) || else
{
int spacing;
for (spacing = pc->column - column; spacing > 0; spacing--)
{
dst += ' ';
column++;
}
dst.append(pc->str);
column += pc->len();
}
}
}
示例10: append
void unc_text::append(const unc_text &ref)
{
if (ref.size() == 0)
{
return;
}
m_logtext.pop_back();
m_logtext.insert(std::end(m_logtext),
std::begin(ref.m_logtext), std::end(ref.m_logtext));
m_chars.insert(m_chars.end(), ref.m_chars.begin(), ref.m_chars.end());
}
示例11: replace
int unc_text::replace(const char *oldtext, const unc_text& newtext)
{
int fidx = find(oldtext);
int olen = strlen(oldtext);
int rcnt = 0;
while (fidx >= 0)
{
rcnt++;
erase(fidx, olen);
insert(fidx, newtext);
fidx = find(oldtext, fidx + newtext.size() - olen + 1);
}
return(rcnt);
}
示例12: equals
bool unc_text::equals(const unc_text& ref) const
{
int len = size();
if (ref.size() != len)
{
return false;
}
for (int idx = 0; idx < len; idx++)
{
if (m_chars[idx] != ref.m_chars[idx])
{
return false;
}
}
return true;
}
示例13: equals
bool unc_text::equals(const unc_text &ref) const
{
const size_t len = size();
if (ref.size() != len)
{
return(false);
}
for (size_t idx = 0; idx < len; idx++)
{
if (m_chars[idx] != ref.m_chars[idx])
{
return(false);
}
}
return(true);
}
示例14: set
void unc_text::set(const unc_text& ref, int idx, int len)
{
int size = ref.size();
fix_len_idx(size, idx, len);
m_logok = false;
if ((idx == 0) && (len == size))
{
m_chars = ref.m_chars;
}
else
{
m_chars.resize(len);
int di = 0;
while (len-- > 0)
{
m_chars[di++] = ref.m_chars[idx++];
}
}
}
示例15: replace
int unc_text::replace(const char *search_text, const unc_text &replace_text)
{
const size_t s_len = strlen(search_text);
const size_t r_len = replace_text.size();
int rcnt = 0;
int fidx = find(search_text);
while (fidx >= 0)
{
rcnt++;
erase(static_cast<size_t>(fidx), s_len);
(static_cast<size_t>(fidx) >= m_chars.size())
? append(replace_text)
: insert(static_cast<size_t>(fidx), replace_text);
fidx = find(search_text, static_cast<size_t>(fidx) + r_len);
}
return(rcnt);
}