Esempio n. 1
0
   /** 
     * parse a given MethodInfo.format() 'ed name and provide
     * the starting and ending indcies of each 
    * @param String* - formatted method name
    * @param int[4]  - array that will be filled with class/method 
    *                  indicies into    
    * @return true, if a class name exists
    */
   bool locateNames(AvmCore* core, Stringp name, int* idx)
   {
       bool hasClass = true;
       VMPI_memset(idx,0,sizeof(*idx));
       if (!name) return false;

       // class
       // idx[0] = 0;
       if ( (idx[1]=name->indexOf(core->newString("."))) >= 0 )
           hasClass = false;  // match means no class name 
       else if ( (idx[1]=name->indexOf(core->newString("$"))) >=0 )
           idx[1]; // match
       else if ( (idx[1]=name->indexOf(core->newString("/"))) >= 0 )
           idx[1]; // match
       else
           hasClass = false;  // nothing looks like a class here

       // method
       if ( (idx[2]=name->lastIndexOf(core->newString("/"))) >= 0 )
           idx[2]++;  // match
       else if ( (idx[2]=name->lastIndexOf(core->kcolon)) >= 0 )
           idx[2]++;  // match
       else
           ;  // idx[2] = 0; 
       idx[3] = name->length()-2; // get rid of paren
               
       return hasClass;
   }
Esempio n. 2
0
    Stringp StringClass::_replace(Stringp subject, Atom pattern, Atom replacementAtom)
    {
        AvmCore* core = this->core();

        ScriptObject *replaceFunction = NULL;
        Stringp replacement = NULL;
        if (AvmCore::istype(replacementAtom, core->traits.function_itraits)) {
            replaceFunction = AvmCore::atomToScriptObject(replacementAtom);
        } else {
            replacement = core->string(replacementAtom);
        }

        if (AvmCore::istype(pattern, core->traits.regexp_itraits)) {
            // RegExp mode
            RegExpObject *reObj = (RegExpObject*) core->atomToScriptObject(pattern);
            if (replaceFunction) {
                return core->string(reObj->replace(subject, replaceFunction));
            } else {
                return core->string(reObj->replace(subject, replacement));
            }

        } else {
            // String replace mode
            Stringp searchString = core->string(pattern);

            int index = subject->indexOf(searchString);
            if (index == -1) {
                // Search string not found; return input unchanged.
                return subject;
            }

            if (replaceFunction) {
                // Invoke the replacement function to figure out the
                // replacement string
                Atom argv[4] = { undefinedAtom,
                                 searchString->atom(),
                                 core->uintToAtom(index),
                                 subject->atom() };
                replacement = core->string(toplevel()->op_call(replaceFunction->atom(),
                                                               3, argv));
            }

            Stringp out = subject->substring(0, index);
            out = String::concatStrings(out, replacement);
            out = String::concatStrings(out, subject->substring(index + searchString->length(), subject->length()));
            return out;
        }
    }