本文整理汇总了C++中tiny_string类的典型用法代码示例。如果您正苦于以下问题:C++ tiny_string类的具体用法?C++ tiny_string怎么用?C++ tiny_string使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了tiny_string类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strcasecmp
/* like strcasecmp(s1.raw_buf(),s2.raw_buf()) but for unicode
* TODO: slow! */
int tiny_string::strcasecmp(tiny_string& s2) const
{
char* str1 = g_utf8_casefold(this->raw_buf(),this->numBytes());
char* str2 = g_utf8_casefold(s2.raw_buf(),s2.numBytes());
int ret = g_utf8_collate(str1,str2);
g_free(str1);
g_free(str2);
return ret;
}
示例2: find
/* start is an index of characters.
* returns index of character */
uint32_t tiny_string::find(const tiny_string& needle, uint32_t start) const
{
//TODO: omit copy into std::string
size_t bytestart = g_utf8_offset_to_pointer(buf,start) - buf;
size_t bytepos = std::string(*this).find(needle.raw_buf(),bytestart,needle.numBytes());
if(bytepos == std::string::npos)
return npos;
else
return g_utf8_pointer_to_offset(buf,buf+bytepos);
}
示例3: call_toJSON
tiny_string Vector::toJSON(std::vector<ASObject *> &path, IFunction *replacer, const tiny_string &spaces, const tiny_string &filter)
{
bool ok;
tiny_string res = call_toJSON(ok,path,replacer,spaces,filter);
if (ok)
return res;
// check for cylic reference
if (std::find(path.begin(),path.end(), this) != path.end())
throwError<TypeError>(kJSONCyclicStructure);
path.push_back(this);
res += "[";
bool bfirst = true;
tiny_string newline = (spaces.empty() ? "" : "\n");
for (unsigned int i =0; i < vec.size(); i++)
{
tiny_string subres;
ASObject* o = vec[i];
if (!o)
o = getSystemState()->getNullRef();
if (replacer != NULL)
{
ASObject* params[2];
params[0] = abstract_di(getSystemState(),i);
params[0]->incRef();
params[1] = o;
params[1]->incRef();
ASObject *funcret=replacer->call(getSystemState()->getNullRef(), params, 2);
if (funcret)
subres = funcret->toJSON(path,NULL,spaces,filter);
}
else
{
subres = o->toJSON(path,replacer,spaces,filter);
}
if (!subres.empty())
{
if (!bfirst)
res += ",";
res += newline+spaces;
bfirst = false;
res += subres;
}
}
if (!bfirst)
res += newline+spaces.substr_bytes(0,spaces.numBytes()/2);
res += "]";
path.pop_back();
return res;
}
示例4: assert_and_throw
const tiny_string multiname::qualifiedString(SystemState* sys) const
{
assert_and_throw(ns.size()>=1);
assert_and_throw(name_type==NAME_STRING);
const tiny_string nsName=sys->getStringFromUniqueId(ns[0].nsNameId);
const tiny_string& name=sys->getStringFromUniqueId(name_s_id);
if(nsName.empty())
return name;
else
{
tiny_string ret=nsName;
ret+="::";
ret+=name;
return ret;
}
}
示例5: parseNumber
int JSON::parseNumber(const tiny_string &jsonstring, int pos, ASObject** parent, const multiname& key)
{
int len = jsonstring.numBytes();
tiny_string res;
bool done = false;
while (!done && pos < len)
{
char c = jsonstring.charAt(pos);
switch(c)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
case '+':
case '.':
case 'E':
case 'e':
res += c;
pos++;
break;
default:
done = true;
break;
}
}
ASString* numstr = Class<ASString>::getInstanceS(res);
number_t num = numstr->toNumber();
if (std::isnan(num))
throwError<SyntaxError>(kJSONInvalidParseInput);
if (*parent == NULL)
*parent = Class<Number>::getInstanceS(num);
else
{
(*parent)->setVariableByMultiname(key,Class<Number>::getInstanceS(num),ASObject::CONST_NOT_ALLOWED);
}
return pos;
}
示例6: parseArray
int JSON::parseArray(const tiny_string &jsonstring, int pos, ASObject** parent, const multiname& key, IFunction *reviver)
{
int len = jsonstring.numChars();
pos++; // ignore '['
ASObject* subobj = Class<Array>::getInstanceS();
if (*parent == NULL)
*parent = subobj;
else
(*parent)->setVariableByMultiname(key,subobj,ASObject::CONST_NOT_ALLOWED);
multiname name(NULL);
name.name_type=multiname::NAME_INT;
name.name_i = 0;
name.ns.push_back(nsNameAndKind("",NAMESPACE));
name.isAttribute = false;
bool done = false;
bool needdata = false;
while (!done && pos < len)
{
while (jsonstring.charAt(pos) == ' ' ||
jsonstring.charAt(pos) == '\t' ||
jsonstring.charAt(pos) == '\n' ||
jsonstring.charAt(pos) == '\r'
)
pos++;
char c = jsonstring.charAt(pos);
switch(c)
{
case ']':
done = true;
pos++;
break;
case ',':
name.name_i++;
needdata = true;
pos++;
break;
default:
pos = parse(jsonstring,pos,&subobj,name, reviver);
needdata = false;
break;
}
}
if (!done || needdata)
throwError<SyntaxError>(kJSONInvalidParseInput);
return pos;
}
示例7: parseAll
void JSON::parseAll(const tiny_string &jsonstring, ASObject** parent , const multiname& key, IFunction *reviver)
{
int len = jsonstring.numBytes();
int pos = 0;
while (pos < len)
{
if (*parent && (*parent)->isPrimitive())
throwError<SyntaxError>(kJSONInvalidParseInput);
pos = parse(jsonstring, pos, parent , key, reviver);
while (jsonstring.charAt(pos) == ' ' ||
jsonstring.charAt(pos) == '\t' ||
jsonstring.charAt(pos) == '\n' ||
jsonstring.charAt(pos) == '\r'
)
pos++;
}
}
示例8: XMLNode
XMLDocument::XMLDocument(Class_base* c, tiny_string s)
: XMLNode(c),rootNode(NULL),ignoreWhite(false)
{
if(!s.empty())
{
parseXMLImpl(s);
}
}
示例9: isValidQName
bool Array::isValidQName(const tiny_string& name, const tiny_string& ns, unsigned int& index)
{
if(ns!="")
return false;
assert_and_throw(!name.empty());
index=0;
//First we try to convert the string name to an index, at the first non-digit
//we bail out
for(auto i=name.begin(); i!=name.end(); ++i)
{
if(!i.isdigit())
return false;
index*=10;
index+=i.digit_value();
}
return true;
}
示例10: isIntegerWithoutLeadingZeros
bool Array::isIntegerWithoutLeadingZeros(const tiny_string& value)
{
if (value.empty())
return false;
else if (value == "0")
return true;
bool first = true;
for (CharIterator it=value.begin(); it!=value.end(); ++it)
{
if (!it.isdigit() || (first && *it == '0'))
return false;
first = false;
}
return true;
}
示例11:
CurlDownloader::CurlDownloader(const tiny_string& u)
{
//TODO: Url encode the string
std::string tmp2;
tmp2.reserve(u.len()*2);
for(int i=0;i<u.len();i++)
{
if(u[i]==' ')
{
char buf[4];
sprintf(buf,"%%%x",(unsigned char)u[i]);
tmp2+=buf;
}
else
tmp2.push_back(u[i]);
}
url=tmp2;
}
示例12: isValidQName
bool Array::isValidQName(const tiny_string& name, const tiny_string& ns, unsigned int& index)
{
if(ns!="")
return false;
assert_and_throw(name.len()!=0);
index=0;
//First we try to convert the string name to an index, at the first non-digit
//we bail out
for(int i=0;i<name.len();i++)
{
if(!isdigit(name[i]))
return false;
index*=10;
index+=(name[i]-'0');
}
return true;
}
示例13: openLink
void nsPluginInstance::openLink(const tiny_string& url, const tiny_string& window)
{
assert(!window.empty());
linkOpenData *data = new linkOpenData;
data->instance = mInstance;
data->url = url;
data->window = window;
NPN_PluginThreadAsyncCall(mInstance, asyncOpenPage, data);
}
示例14: connect
void XMLSocket::connect(tiny_string host, int port)
{
if (port <= 0 || port > 65535)
throw Class<SecurityError>::getInstanceS(getSystemState(),"Invalid port");
if (host.empty())
host = getSys()->mainClip->getOrigin().getHostname();
if (isConnected())
throw Class<IOError>::getInstanceS(getSystemState(),"Already connected");
// Host shouldn't contain scheme or port
if (host.strchr(':') != NULL)
throw Class<SecurityError>::getInstanceS(getSystemState(),"Invalid hostname");
// Check sandbox and policy file
size_t buflen = host.numBytes() + 22;
char *urlbuf = g_newa(char, buflen);
snprintf(urlbuf, buflen, "xmlsocket://%s:%d", host.raw_buf(), port);
URLInfo url(urlbuf);
getSystemState()->securityManager->checkURLStaticAndThrow(url,
~(SecurityManager::LOCAL_WITH_FILE),
SecurityManager::LOCAL_WITH_FILE | SecurityManager::LOCAL_TRUSTED,
true);
SecurityManager::EVALUATIONRESULT evaluationResult;
evaluationResult = getSys()->securityManager->evaluateSocketConnection(url, true);
if(evaluationResult != SecurityManager::ALLOWED)
{
incRef();
getVm(getSystemState())->addEvent(_MR(this), _MR(Class<SecurityErrorEvent>::getInstanceS(getSystemState(),"No policy file allows socket connection")));
return;
}
incRef();
XMLSocketThread *thread = new XMLSocketThread(_MR(this), host, port, timeout);
getSys()->addJob(thread);
job = thread;
}
示例15: removeWhitespace
tiny_string XMLBase::removeWhitespace(tiny_string val)
{
bool bwhite = true;
uint32_t start = 0;
CharIterator it = val.begin();
CharIterator itend = val.begin();
while (it != val.end())
{
if (!g_unichar_isspace(*it))
{
itend=it;
itend++;
bwhite = false;
}
else if (bwhite)
start++;
it++;
}
if (bwhite)
return "";
return val.substr(start,itend);
}