当前位置: 首页>>代码示例>>C++>>正文


C++ ListIterator::dispatchToString方法代码示例

本文整理汇总了C++中ListIterator::dispatchToString方法的典型用法代码示例。如果您正苦于以下问题:C++ ListIterator::dispatchToString方法的具体用法?C++ ListIterator::dispatchToString怎么用?C++ ListIterator::dispatchToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ListIterator的用法示例。


在下文中一共展示了ListIterator::dispatchToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: call

// ECMA 15.5.4.2 - 15.5.4.20
Value StringProtoFuncImp::call(ExecState *exec, Object &thisObj, const List &args)
{
  Value result;

  // toString and valueOf are no generic functions.
  if (id == ToString || id == ValueOf) {
    KJS_CHECK_THIS( StringInstanceImp, thisObj );

    return String(thisObj.internalValue().toString(exec));
  }

  int n, m;
  UString u2, u3;
  double dpos;
  int pos, p0, i;
  double d = 0.0;

  UString s = thisObj.toString(exec);

  int len = s.size();
  Value a0 = args[0];
  Value a1 = args[1];

  switch (id) {
  case ToString:
  case ValueOf:
    // handled above
    break;
  case CharAt:
    pos = a0.type() == UndefinedType ? 0 : a0.toInteger(exec);
    if (pos < 0 || pos >= len)
      s = "";
    else
      s = s.substr(pos, 1);
    result = String(s);
    break;
  case CharCodeAt:
    pos = a0.type() == UndefinedType ? 0 : a0.toInteger(exec);
    if (pos < 0 || pos >= len)
      d = NaN;
    else {
      UChar c = s[pos];
      d = (c.high() << 8) + c.low();
    }
    result = Number(d);
    break;
  case Concat: {
    ListIterator it = args.begin();
    for ( ; it != args.end() ; ++it) {
        s += it->dispatchToString(exec);
    }
    result = String(s);
    break;
  }
  case IndexOf:
    u2 = a0.toString(exec);
    if (a1.type() == UndefinedType)
      pos = 0;
    else
      pos = a1.toInteger(exec);
    d = s.find(u2, pos);
    result = Number(d);
    break;
  case LastIndexOf:
    u2 = a0.toString(exec);
    d = a1.toNumber(exec);
    if (a1.type() == UndefinedType || KJS::isNaN(d))
      dpos = len;
    else {
      dpos = d;
      if (dpos < 0)
        dpos = 0;
      else if (dpos > len)
        dpos = len;
    }
    result = Number(s.rfind(u2, int(dpos)));
    break;
  case Match:
  case Search: {
    RegExp *reg, *tmpReg = 0;
    RegExpImp *imp = 0;
    if (a0.isA(ObjectType) && a0.toObject(exec).inherits(&RegExpImp::info))
    {
      imp = static_cast<RegExpImp *>( a0.toObject(exec).imp() );
      reg = imp->regExp();
    }
    else
    { /*
       *  ECMA 15.5.4.12 String.prototype.search (regexp)
       *  If regexp is not an object whose [[Class]] property is "RegExp", it is
       *  replaced with the result of the expression new RegExp(regexp).
       */
      reg = tmpReg = new RegExp(a0.toString(exec), RegExp::None);
    }
    RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->interpreter()->builtinRegExp().imp());
    int **ovector = regExpObj->registerRegexp(reg, s);
    reg->prepareMatch(s);
    UString mstr = reg->match(s, -1, &pos, ovector);
    if (id == Search) {
//.........这里部分代码省略.........
开发者ID:burlog,项目名称:kjscompress,代码行数:101,代码来源:string_object.cpp


注:本文中的ListIterator::dispatchToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。