Exemplo n.º 1
0
void jsvStringIteratorNew(JsvStringIterator *it, JsVar *str, size_t startIdx) {
  assert(jsvHasCharacterData(str));
  it->var = jsvLockAgain(str);
  it->charsInVar = jsvGetCharactersInVar(str);
  if (jsvIsFlatString(str)) {
    /* Flat strings use the first var to store the size, and subsequent vars
       to store the actual data, so we tweak charIdx to handle this */
    it->varIndex = -sizeof(JsVar);
    it->charsInVar += sizeof(JsVar);
    it->charIdx = sizeof(JsVar)+startIdx;
  } else {
    it->varIndex = 0;
    it->charIdx = startIdx;
  }
  while (it->charIdx>0 && it->charIdx >= it->charsInVar) {
    it->charIdx -= it->charsInVar;
    it->varIndex += it->charsInVar;
    if (it->var) {
      if (jsvGetLastChild(it->var)) {
        JsVar *next = jsvLock(jsvGetLastChild(it->var));
        jsvUnLock(it->var);
        it->var = next;
        it->charsInVar = jsvGetCharactersInVar(it->var);
      } else {
        jsvUnLock(it->var);
        it->var = 0;
        it->charsInVar = 0;
        it->varIndex = startIdx - it->charIdx;
        return; // at end of string - get out of loop
      }
    }
  }
}
Exemplo n.º 2
0
void jsvStringIteratorNew(JsvStringIterator *it, JsVar *str, size_t startIdx) {
  assert(jsvHasCharacterData(str));
  it->var = jsvLockAgain(str);
  it->varIndex = 0;
  it->charsInVar = jsvGetCharactersInVar(str);
  it->charIdx = startIdx;
  if (jsvIsFlatString(str)) {
    it->ptr = jsvGetFlatStringPointer(it->var);
  } else if (jsvIsNativeString(str)) {
    it->ptr = (char*)it->var->varData.nativeStr.ptr;
  } else{
    it->ptr = &it->var->varData.str[0];
  }
  while (it->charIdx>0 && it->charIdx >= it->charsInVar) {
    it->charIdx -= it->charsInVar;
    it->varIndex += it->charsInVar;
    if (it->var) {
      if (jsvGetLastChild(it->var)) {
        JsVar *next = jsvLock(jsvGetLastChild(it->var));
        jsvUnLock(it->var);
        it->var = next;
        it->ptr = &next->varData.str[0];
        it->charsInVar = jsvGetCharactersInVar(it->var);
      } else {
        jsvUnLock(it->var);
        it->var = 0;
        it->ptr = 0;
        it->charsInVar = 0;
        it->varIndex = startIdx - it->charIdx;
        return; // at end of string - get out of loop
      }
    }
  }
}
Exemplo n.º 3
0
void jsvStringIteratorNew(JsvStringIterator *it, JsVar *str, size_t startIdx) {
  assert(jsvHasCharacterData(str));
  it->var = jsvLockAgain(str);
  it->charsInVar = jsvGetCharactersInVar(str);
  it->charIdx = startIdx;
  it->varIndex = 0;
  while (it->charIdx>0 && it->charIdx >= it->charsInVar) {
    it->charIdx -= it->charsInVar;
    it->varIndex += it->charsInVar;
    if (it->var) {
      if (jsvGetLastChild(it->var)) {
        JsVar *next = jsvLock(jsvGetLastChild(it->var));
        jsvUnLock(it->var);
        it->var = next;
        it->charsInVar = jsvGetCharactersInVar(it->var);
      } else {
        jsvUnLock(it->var);
        it->var = 0;
        it->charsInVar = 0;
        it->varIndex = startIdx - it->charIdx;
        return; // at end of string - get out of loop
      }
    }
  }
  it->varIndex = startIdx - it->charIdx;
}
Exemplo n.º 4
0
void jsvStringIteratorGotoEnd(JsvStringIterator *it) {
  assert(it->var);
  while (jsvGetLastChild(it->var)) {
    JsVar *next = jsvLock(jsvGetLastChild(it->var));
    jsvUnLock(it->var);
    it->var = next;
    it->varIndex += it->charsInVar;
    it->charsInVar = jsvGetCharactersInVar(it->var);
  }
  if (it->charsInVar) it->charIdx = it->charsInVar-1;
  else it->charIdx = 0;
}
Exemplo n.º 5
0
// EDIT //
void jsvStringIteratorNext(JsvStringIterator *it) {
//  jsvStringIteratorNextInline(it);
	it->charIdx++;
	if (it->charIdx >= it->charsInVar) {
		it->charIdx -= it->charsInVar;
		if (it->var && jsvGetLastChild(it->var)) {
			JsVar *next = jsvLock(jsvGetLastChild(it->var));
			jsvUnLock(it->var);
			it->var = next;
			it->varIndex += it->charsInVar;
			it->charsInVar = jsvGetCharactersInVar(it->var);
		} else {
			jsvUnLock(it->var);
			it->var = 0;
			it->varIndex += it->charsInVar;
			it->charsInVar = 0;
		}
	}
}
Exemplo n.º 6
0
/// Move on to the next character
static void NO_INLINE jslGetNextCh(JsLex *lex) {
  lex->currCh = jslNextCh(lex);

  lex->it.charIdx++;
  if (lex->it.charIdx >= lex->it.charsInVar) {
    lex->it.charIdx -= lex->it.charsInVar;
    if (lex->it.var && lex->it.var->lastChild) {
      JsVar *next = jsvLock(lex->it.var->lastChild);
      jsvUnLock(lex->it.var);
      lex->it.var = next;
      lex->it.varIndex += lex->it.charsInVar;
      lex->it.charsInVar = jsvGetCharactersInVar(lex->it.var);
    } else {
      jsvUnLock(lex->it.var);
      lex->it.var = 0;
      lex->it.varIndex += lex->it.charsInVar;
      lex->it.charsInVar = 0;
    }
  }
}
Exemplo n.º 7
0
/// Move on to the next character
static void NO_INLINE jslGetNextCh(JsLex *lex) {
  lex->currCh = jslNextCh(lex);

  /** NOTE: In this next bit, we DON'T LOCK OR UNLOCK.
   * The String iterator we're basing on does, so every
   * time we touch the iterator we have to re-lock it
   */
  lex->it.charIdx++;
  if (lex->it.charIdx >= lex->it.charsInVar) {
    lex->it.charIdx -= lex->it.charsInVar;
    if (lex->it.var && jsvGetLastChild(lex->it.var)) {
      lex->it.var = _jsvGetAddressOf(jsvGetLastChild(lex->it.var));
      lex->it.varIndex += lex->it.charsInVar;
      lex->it.charsInVar = jsvGetCharactersInVar(lex->it.var);
    } else {
      lex->it.var = 0;
      lex->it.varIndex += lex->it.charsInVar;
      lex->it.charsInVar = 0;
    }
  }
}