本文整理汇总了C++中StringDataPtr::stringValue方法的典型用法代码示例。如果您正苦于以下问题:C++ StringDataPtr::stringValue方法的具体用法?C++ StringDataPtr::stringValue怎么用?C++ StringDataPtr::stringValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringDataPtr
的用法示例。
在下文中一共展示了StringDataPtr::stringValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strtod
void
FreezeScript::TransformVisitor::visitDouble(const DoubleDataPtr& dest)
{
Slice::TypePtr type = dest->getType();
if(_info->doDefaultTransform(type))
{
DoubleDataPtr d = DoubleDataPtr::dynamicCast(_src);
if(d)
{
dest->setValue(d->doubleValue());
}
else
{
StringDataPtr s = StringDataPtr::dynamicCast(_src);
if(s)
{
string str = s->stringValue();
const char* start = str.c_str();
char* end;
double v = strtod(start, &end);
if(errno == ERANGE)
{
rangeError(str, type);
}
else
{
while(*end)
{
if(!isspace(*end))
{
conversionError(type, _src->getType(), str);
return;
}
end++;
}
if(!*end)
{
dest->setValue(v);
}
}
}
else
{
typeMismatchError(type, _src->getType());
}
}
}
_info->executeCustomTransform(dest, _src);
}
示例2: if
bool
FreezeScript::invokeMemberFunction(const string& name, const DataPtr& target, const DataList& args, DataPtr& result,
const DataFactoryPtr& factory, const ErrorReporterPtr& errorReporter)
{
//
// string
//
StringDataPtr targetStr = StringDataPtr::dynamicCast(target);
if(targetStr)
{
if(name == "find")
{
StringDataPtr argData;
IntegerDataPtr startData;
if(args.size() > 0)
{
argData = StringDataPtr::dynamicCast(args[0]);
}
if(args.size() > 1)
{
startData = IntegerDataPtr::dynamicCast(args[1]);
}
if(args.size() == 0 || args.size() > 2 || !argData || (args.size() == 2 && !startData))
{
errorReporter->error("invalid arguments to find(string str[, int len])");
}
string targ = targetStr->stringValue();
string arg = argData->stringValue();
string::size_type pos;
if(startData)
{
string::size_type start = static_cast<string::size_type>(startData->integerValue());
pos = targ.find(arg, start);
}
else
{
pos = targ.find(arg);
}
result = factory->createInteger(pos == string::npos ? -1 : static_cast<Ice::Long>(pos), false);
return true;
}
else if(name == "substr")
{
IntegerDataPtr startData;
IntegerDataPtr lenData;
if(args.size() > 0)
{
startData = IntegerDataPtr::dynamicCast(args[0]);
}
if(args.size() > 1)
{
lenData = IntegerDataPtr::dynamicCast(args[1]);
}
if(args.size() == 0 || args.size() > 2 || !startData || (args.size() == 2 && !lenData))
{
errorReporter->error("invalid arguments to substr(int start[, int len])");
}
string targ = targetStr->stringValue();
string::size_type start = static_cast<string::size_type>(startData->integerValue());
string::size_type len = string::npos;
if(lenData)
{
len = static_cast<string::size_type>(lenData->integerValue());
}
if(start > targ.size())
{
ostringstream ostr;
ostr << "substr() starting position (" << start << ") is greater than string length ("
<< targ.size() << ")";
errorReporter->error(ostr.str());
}
result = factory->createString(targ.substr(start, len), false);
return true;
}
else if(name == "replace")
{
IntegerDataPtr startData;
IntegerDataPtr lenData;
StringDataPtr strData;
if(args.size() == 3)
{
startData = IntegerDataPtr::dynamicCast(args[0]);
lenData = IntegerDataPtr::dynamicCast(args[1]);
strData = StringDataPtr::dynamicCast(args[2]);
}
if(args.size() != 3 || !startData || !lenData || !strData)
{
errorReporter->error("invalid arguments to replace(int start, int len, string val)");
}
string targ = targetStr->stringValue();
string::size_type start = static_cast<string::size_type>(startData->integerValue());
string::size_type len = static_cast<string::size_type>(lenData->integerValue());
string str = strData->stringValue();
if(start > targ.size())
{
ostringstream ostr;
ostr << "replace() starting position (" << start << ") is greater than string length ("
<< targ.size() << ")";
errorReporter->error(ostr.str());
}
//.........这里部分代码省略.........