本文整理汇总了C++中StringRef::length方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::length方法的具体用法?C++ StringRef::length怎么用?C++ StringRef::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringRef
的用法示例。
在下文中一共展示了StringRef::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: endswith
/// Check if this string ends with the given \p Suffix.
bool StringRef::endswith(StringRef pSuffix) const
{
return (m_Length >= pSuffix.length() &&
0 == compareMemory(end() - pSuffix.length(),
pSuffix.data(),
pSuffix.length()));
}
示例2: startsWith
bool String::startsWith(const StringRef& strRef) const
{
if (len < strRef.length())
{
return false;
}
return ::memcmp(data(), strRef.data(), strRef.length()) == 0;
}
示例3: endsWith
bool String::endsWith(const StringRef& strRef) const
{
if (len < strRef.length())
{
return false;
}
size_t refLen = strRef.length();
return ::memcmp(data() + len - refLen, strRef.data(), refLen) == 0;
}
示例4: split
void split(const StringRef & txt, const StringRef & splitter, tStringVector & list, bool all) {
unsigned int start = 0, end;
list.clear();
while (start < txt.length()) { // dopóki jest co kopiowaæ
end = txt.find(splitter, start);
if (all || start != end)
list.push_back(txt.substr(start, (end == -1 ? end : end - start)) );
if (end == -1)
break;
start = end + splitter.length();
}
}
示例5: toInteger
int TILParser::toInteger(StringRef s) {
char* end = nullptr;
long long val = strtol(s.c_str(), &end, 0);
// FIXME: some proper error handling here?
assert(end == s.c_str() + s.length() && "Could not parse string.");
return static_cast<int>(val);
}
示例6:
bool ff::Value::CreateString(StringRef str, Value **ppValue)
{
assertRetVal(ppValue, false);
if (!str.length())
{
static Value::StaticValue s_data;
static Value *s_val = nullptr;
if (!s_val)
{
ScopeStaticValueAlloc scopeAlloc;
if (!s_val)
{
s_val = s_data.AsValue();
s_val->Value::Value();
s_val->SetType(Type::String);
s_val->InternalGetString().String::String();
}
}
*ppValue = s_val;
}
else
{
*ppValue = NewValueOneRef();
(*ppValue)->SetType(Type::String);
(*ppValue)->InternalGetString().String::String(str);
}
return true;
}
示例7: toDouble
double TILParser::toDouble(StringRef s) {
char* end = nullptr;
double val = strtod(s.c_str(), &end);
// FIXME: some proper error handling here?
assert(end == s.c_str() + s.length() && "Could not parse string.");
return val;
}
示例8: compare
int32 String::compare(const StringRef& strRef) const
{
size_t strRefLen = strRef.length();
const char* localData = data();
const char* strRefData = strRef.data();
// Emulate behavior of strcmp. That is, do comparison as if the StringRef
// was nul terminated.
if (len == strRefLen)
{
return ::memcmp(localData, strRefData, len);
}
else if (len < strRefLen)
{
int32 partial = ::memcmp(localData, strRefData, len);
if (partial != 0)
return partial;
return 1;
}
else
{
int32 partial = ::memcmp(localData, strRefData, strRefLen);
if (partial != 0)
return partial;
return -1;
}
}
示例9: format
String format(const StringRef& fmt, Args... args) {
const size_t num_args = sizeof...(args);
String converted[num_args];
convert_variadic_arguments_to_strings(converted, args...);
StringBuffer buffer;
const char* c = fmt.c_str();
bool escaping = false;
for (size_t i = 0; i < fmt.length(); ++i) {
switch (c[i]) {
case '\\': {
if (escaping) { escaping = false; buffer.push('\\'); continue; }
escaping = true;
continue;
}
case '{': {
if (!escaping) {
size_t idx = 0;
bool valid = true;
bool anything = false;
size_t j = i + 1;
for (; j < fmt.length(); ++j) {
if (is_numeric(c[j])) {
idx *= 10;
idx += c[j] - '0';
anything = true;
} else if (c[j] == '}') {
break;
} else {
// non-numeric, non-terminator
valid = false;
break;
}
}
if (valid && anything && idx < num_args) {
buffer << converted[idx];
i = j;
continue;
}
}
}
}
escaping = false;
buffer.push(c[i]);
}
return buffer.to_string();
}
示例10:
const String operator+(const String& str, const StringRef& strRef)
{
String ret;
ret.reserve(str.length() + strRef.length());
ret.append(str);
ret.append(strRef);
return ret;
}
示例11: parseLocaleDouble
double Double::parseLocaleDouble(StringRef strRef, bool* ok)
{
std::stringstream ss;
float ret;
ss.write(strRef.data(), strRef.length());
ss >> ret;
// Check that parsing did not fail and that every character was used
if (!ss.fail() && (ss.tellg() == (std::streampos)strRef.length()))
{
Bool::setBool(ok, true);
return ret;
}
else
{
Bool::setBool(ok, false);
return 0.0;
}
}
示例12: createLines
static void createLines (Array<CodeDocumentLine*>& newLines, StringRef text)
{
String::CharPointerType t (text.text);
int charNumInFile = 0;
bool finished = false;
while (! (finished || t.isEmpty()))
{
String::CharPointerType startOfLine (t);
int startOfLineInFile = charNumInFile;
int lineLength = 0;
int numNewLineChars = 0;
for (;;)
{
const juce_wchar c = t.getAndAdvance();
if (c == 0)
{
finished = true;
break;
}
++charNumInFile;
++lineLength;
if (c == '\r')
{
++numNewLineChars;
if (*t == '\n')
{
++t;
++charNumInFile;
++lineLength;
++numNewLineChars;
}
break;
}
if (c == '\n')
{
++numNewLineChars;
break;
}
}
newLines.add (new CodeDocumentLine (startOfLine, t, lineLength,
numNewLineChars, startOfLineInFile));
}
jassert (charNumInFile == text.length());
}
示例13: test_chunkedwriter_basic
// Tests basic chunked writer functionality
bool test_chunkedwriter_basic() {
WriteTestSource streamSource;
ChunkedWriter writer;
writer.init(&streamSource);
HttpError err = writer.write("0123456789", 10);
if (err != HttpError::Ok) {
testf("Write failed");
return false;
}
err = writer.write("abcd", 4);
if (err != HttpError::Ok) {
testf("Write failed");
return false;
}
err = writer.close();
if (err != HttpError::Ok) {
testf("Close failed");
return false;
}
const StringRef expected =
"A\r\n"
"0123456789\r\n"
"4\r\n"
"abcd\r\n"
"0\r\n"
"\r\n";
if (streamSource.dataWritten.size() != expected.length() ||
std::memcmp(&streamSource.dataWritten[0], expected.data(), expected.length()) != 0) {
testf("Did not write expected data");
return false;
}
return true;
}
示例14: writeString
void BinaryWriter::writeString(const StringRef& str, ln::TextEncoding* encoding)
{
if (encoding) {
LN_NOTIMPLEMENTED();
return;
}
if (ln::Environment::byteOrder() == ByteOrder::BigEndian) {
LN_NOTIMPLEMENTED();
return;
}
write(str.data(), str.length() * sizeof(Char));
}
示例15: findLastNotOf
size_t StringRef::findLastNotOf(StringRef charList, size_t from) const
{
std::bitset<1 << CHAR_BIT> charBits;
for (size_t i = 0; charList.length() != i; ++i)
charBits.set(static_cast<uchar>(charList[i]));
for (size_t i = std::min(from, mLength) - 1; npos != i; --i)
if (!charBits.test(static_cast<uchar>(mData[i])))
return i;
return npos;
}