Exemplo n.º 1
0
bool Uri::Private::parsePchar()
{
    const Char curr = m_uri[m_parserPos];
    const iuint32 currValue = curr.value();
    if (!currValue) {
        return false;
    }
    if (currValue < 128 && isUnreserved[currValue]) {
        m_parserAux += curr;
        ++m_parserPos;
        return true;
    }
    const size_t parserOldPos = m_parserPos;
    if (parsePctEncoded()) {
        return true;
    }
    m_parserPos = parserOldPos;
    if (currValue < 128 && isSubdelim[currValue]) {
        m_parserAux += curr;
        ++m_parserPos;
        return true;
    }
    if (curr == ':' || curr == '@') {
        m_parserAux += curr;
        ++m_parserPos;
        return true;
    }
    return false;
}
Exemplo n.º 2
0
bool Uri::Private::parseSegmentNzNc()
{
    bool res = false;
    while (true) {
        const Char curr = m_uri[m_parserPos];
        const iuint32 currValue = curr.value();
        if (currValue < 128 && isUnreserved[currValue]) {
            m_parserAux += curr;
            ++m_parserPos;
            res = true;
            continue;
        }
        const size_t parserOldPos = m_parserPos;
        if (parsePctEncoded()) {
            res = true;
            continue;
        }
        m_parserPos = parserOldPos;
        if (currValue < 128 && isSubdelim[currValue]) {
            m_parserAux += curr;
            ++m_parserPos;
            res = true;
            continue;
        }
        if (curr == '@') {
            m_parserAux += '@';
            ++m_parserPos;
            res = true;
            continue;
        }
        return res;
    }
}
Exemplo n.º 3
0
TEST(VersionTest, SelfAssignmentAfterOperations) {
    Int a = 3;
    Int b = any_int("B");
    Char c = 'c';

    EXPECT_EQ(0, a.get_version());
    EXPECT_EQ(0, b.get_version());
    EXPECT_EQ(0, c.get_version());

    // some operations
    a = a + b + c;
    b = a + b + c;
    b = 5;
    c = c + 'x';
    c = 'y';
    c = 'z' + c;

    EXPECT_EQ(1, a.get_version());
    EXPECT_EQ(2, b.get_version());
    EXPECT_EQ(3, c.get_version());

    a = a;
    b = b;
    c = c;

    EXPECT_EQ(1, a.get_version());
    EXPECT_EQ(2, b.get_version());
    EXPECT_EQ(3, c.get_version());
}
Exemplo n.º 4
0
bool Uri::Private::parseDecOctet()
{
    String decOctet;
    for (size_t i = 0; i < 3; ++i) {
        const Char currChar = m_uri[m_parserPos];
        const iuint32 currValue = currChar.value();
        if (currValue && currValue < 128 && isDigit[currValue]) {
            decOctet += currChar;
            ++m_parserPos;
        } else {
            break;
        }
    }
    if (decOctet.empty()) {
        return false;
    } else {
        const size_t retValue = decOctet.toInt();
        if (retValue < 256) {
            m_parserAux += decOctet;
            return true;
        } else {
            return false;
        }
    }
}
Exemplo n.º 5
0
bool Uri::Private::parseIPvFuture()
{
    if (!expectChar('v') && !expectChar('V')) {
        return false;
    }
    m_parserAux.clear();
    Char curr = m_uri[m_parserPos];
    size_t currValue = curr.value();
    if (currValue > 127 || !isHexdig[currValue]) {
        return false;
    }
    ++m_parserPos;
    if (!expectChar('.')) {
        return false;
    }
    curr = m_uri[m_parserPos];
    currValue = curr.value();
    if (currValue < 128 && isUnreserved[currValue]) {
        ++m_parserPos;
        return true;
    }
    if (currValue < 128 && isSubdelim[currValue]) {
        ++m_parserPos;
        return true;
    }
    if (curr == ':') {
        ++m_parserPos;
        return true;
    }
    return false;
}
Exemplo n.º 6
0
bool JsonParser::JsonStringParser::advance(Char ch)
{
    switch (_state)
    {
        case state_0:
            if (ch == '\\')
                _state = state_esc;
            else if (ch == '"')
                return true;
            else
                _str += ch;
            break;

        case state_esc:
            _state = state_0;
            if (ch == '"' || ch == '\\' || ch == '/')
                _str += ch;
            else if (ch == 'b')
                _str += '\b';
            else if (ch == 'f')
                _str += '\f';
            else if (ch == 'n')
                _str += '\n';
            else if (ch == 'r')
                _str += '\r';
            else if (ch == 't')
                _str += '\t';
            else if (ch == 'u')
            {
                _value = 0;
                _count = 4;
                _state = state_hex;
            }
            else
                _jsonParser->doThrow(std::string("invalid character '") + ch.narrow() + "' in string");
            break;

        case state_hex:
            if (ch >= '0' && ch <= '9')
                _value = (_value << 4) | (ch.value() - '0');
            else if (ch >= 'a' && ch <= 'f')
                _value = (_value << 4) | (ch.value() - 'a' + 10);
            else if (ch >= 'A' && ch <= 'F')
                _value = (_value << 4) | (ch.value() - 'A' + 10);
            else
                _jsonParser->doThrow(std::string("invalid character '") + ch.narrow() + "' in hex sequence");

            if (--_count == 0)
            {
                _str += Char(static_cast<wchar_t>(_value));
                _state = state_0;
            }

            break;

    }

    return false;
}
Exemplo n.º 7
0
TEST(VersionTest, InitWithVarRequiringCast) {
    Bool a = any_bool("A");
    Char b = any_char("B");
    Int c = b;

    EXPECT_EQ(0, a.get_version());
    EXPECT_EQ(0, b.get_version());
    EXPECT_EQ(0, c.get_version());
}
Exemplo n.º 8
0
TEST(VersionTest, InitWithAny) {
    Bool a = any_bool("A");
    Char b = any_char("B");
    Int c = any_int("C");

    EXPECT_EQ(0, a.get_version());
    EXPECT_EQ(0, b.get_version());
    EXPECT_EQ(0, c.get_version());
}
Exemplo n.º 9
0
void Line::SetText( string _character )
{
    Char * character = new Char();
    vector<Char *>::iterator it = characters.begin() + active;

    character->SetText( _character );
    characters.insert( it, character );
    IncrementParams( 1 );
}
Exemplo n.º 10
0
Char* Line::Delete(int x) {
  if ((size_t)x >= m_chars.size()) {
    throw ISError("Cannot insert; x out of bounds");
  }
  Char* c = m_chars.at(x);
  c->Unlink();
  m_charpool.Unlink(*c);
  m_chars.erase(m_chars.begin() + x);
  return c;
}
Exemplo n.º 11
0
bool Uri::Private::expectChar(Char c)
{
    const Char curr = m_uri[m_parserPos];
    const iuint32 currValue = curr.value();
    if (!currValue || currValue > 127 || curr != c) {
        return false;
    }
    ++m_parserPos;
    return true;
}
Exemplo n.º 12
0
TEST(VersionTest, InitWithConcrete) {
    Bool a = true;
    Bool b = true;
    Char c = 'a';
    Int d = 3;

    EXPECT_EQ(0, a.get_version());
    EXPECT_EQ(0, b.get_version());
    EXPECT_EQ(0, c.get_version());
    EXPECT_EQ(0, d.get_version());
}
Exemplo n.º 13
0
bool Uri::Private::parseReserved()
{
    const Char curr = m_uri[m_parserPos];
    const iuint32 currValue = curr.value();
    if (currValue < 128 && (isGendelim[currValue] || isSubdelim[currValue])) {
        m_parserAux += curr;
        ++m_parserPos;
        return true;
    }
    
    return false;
}
Exemplo n.º 14
0
bool Uri::Private::parseH16()
{
    for (size_t i = 0; i < 4; ++i) {
        const Char curr = m_uri[m_parserPos];
        const size_t currValue = curr.value();
        if (!currValue || currValue > 127 || !isHexdig[currValue]) {
            return i;
        }
        m_parserAux += curr;
        ++m_parserPos;
    }
    return true;
}
Exemplo n.º 15
0
void Uri::Private::parsePort()
{
    m_parserAux.clear();
    Char curr = m_uri[m_parserPos];
    iuint32 currValue = curr.value();
    while (currValue && currValue < 128 && isDigit[currValue]) {
        m_parserAux += curr;
        m_parserPos++;
        curr = m_uri[m_parserPos];
        currValue = curr.value();
    }
    m_port = m_parserAux.empty() ? -1 : m_parserAux.toInt();
}
Exemplo n.º 16
0
String Uri::Private::getHex(Char ch) const
{
    String res;
    union {
        iuint32 value;
        ichar v[4];
    } fragmentedValue;
    fragmentedValue.value = ch.value();
    const iint32 octetsRequired = ch.octetsRequired();
    for (iint32 i = 0; i < octetsRequired; ++i) {
        res += '%';
        res += uri_hex[(fragmentedValue.v[octetsRequired - i - 1] >> 4) & 0xf];
        res += uri_hex[fragmentedValue.v[octetsRequired - i - 1] & 0xf];
    }
    return res;
}
void EpsilonNFA::NFAGenerator::visit(Char& node)
{
    _pool.push_back(std::make_unique<Node>());
    auto newNode = _pool.back().get();
    start->edges.push_back(Edge{ node.ch(), newNode });
    end = newNode;
    end->stateInfo = _info;
}
Exemplo n.º 18
0
TEST(VersionTest, SelfAssignmentAfterInit) {
    Int a = 3;
    Int b = any_int("B");
    Char c = 'c';

    EXPECT_EQ(0, a.get_version());
    EXPECT_EQ(0, b.get_version());
    EXPECT_EQ(0, c.get_version());

    a = a;
    b = b;
    c = c;

    EXPECT_EQ(0, a.get_version());
    EXPECT_EQ(0, b.get_version());
    EXPECT_EQ(0, c.get_version());
}
Exemplo n.º 19
0
void EntityResolver::getEntity(std::basic_ostream<Char>& os, Char ch) const
{
    unsigned u = 0;
    unsigned o = sizeof(rent)/sizeof(Ent) - 1;
    while (o - u > 1)
    {
        unsigned m = (o + u) / 2;
        if (rent[m].charValue == ch.value())
        {
            printEntity(os, rent[m].entity);
            return;
        }

        if (ch.value() < rent[m].charValue)
            o = m;
        else
            u = m;
    }

    if (rent[u].charValue == ch.value())
        printEntity(os, rent[u].entity);
    else if (rent[o].charValue == ch.value())
        printEntity(os, rent[o].entity);
    else if (ch.value() >= ' ' && ch.value() <= 0x7F)
        os << ch;
    else
        os << Char('&') << Char('#') << static_cast<uint32_t>(ch.value()) << Char(';');
}
Exemplo n.º 20
0
bool Uri::Private::parseScheme()
{
    m_parserAux.clear();
    Char curr = m_uri[m_parserPos];
    iuint32 currValue = curr.value();
    if (!currValue || currValue > 127 || !isAlpha[currValue]) {
        return false;
    }
    while (currValue && currValue < 128 && (isAlpha[currValue] || isDigit[currValue] ||
                                            curr == '+' || curr == '-' || curr == '.')) {
        m_parserAux += curr;
        ++m_parserPos;
        curr = m_uri[m_parserPos];
        currValue = curr.value();
    }
    m_scheme = m_parserAux;
    return true;
}
Exemplo n.º 21
0
void Uri::Private::parseUserinfo()
{
    m_parserAux.clear();
    bool usernameFound = false;
    while (true) {
        const Char curr = m_uri[m_parserPos];
        const iuint32 currValue = curr.value();
        if (!currValue) {
            return;
        }
        if (currValue < 128 && isUnreserved[currValue]) {
            if (!usernameFound && curr == ':') {
                usernameFound = true;
            } else if (!usernameFound) {
                m_username += curr;
            } else {
                m_password += curr;
            }
            m_parserAux += curr;
            ++m_parserPos;
            continue;
        }
        const size_t parserOldPos = m_parserPos;
        if (parsePctEncoded()) {
            continue;
        }
        m_parserPos = parserOldPos;
        if (currValue < 128 && (isSubdelim[currValue] ||
                                curr == ':')) {
            if (!usernameFound && curr == ':') {
                usernameFound = true;
            } else if (!usernameFound) {
                m_username += curr;
            } else {
                m_password += curr;
            }
            m_parserAux += curr;
            ++m_parserPos;
            continue;
        }
        m_userInfo = m_parserAux;
        return;
    }
}
Exemplo n.º 22
0
void DocState::Deserialize(std::ifstream & ifs){
    // Dummy objects
    Char    ch(logger);
    Graph   g(logger);
    Table   t(logger);
    Eof     e(logger);

    uint32 magic;
    while(!ifs.eof()){
        DESER_OBJ(magic);
        if(magic == offset_magic){
            // offset is placed at the end of the serialized record
            DESER_OBJ(glyphAttrib);
            DESER_OBJ(lineAttrib);
            return;
        }
        else if (magic == e.GetMagic()){
            Eof * pe = new Eof(logger);
            buffer.push_back(pe);
            pe->Deserialize(ifs);
        }
        else if (magic == ch.GetMagic()){
            Char* pch = new Char(logger);
            buffer.push_back(pch);
            pch->Deserialize(ifs);
        }
        else if (magic == g.GetMagic()){
            Graph* pg = new Graph(logger);
            buffer.push_back(pg);
            pg->Deserialize(ifs);
        }
        else if (magic == t.GetMagic()){
            Table* pt = new Table(logger);
            buffer.push_back(pt);
            pt->Deserialize(ifs);
        }
        else{
            LOG_ERROR("Unsupported class magic.");
        }
    }
}
Exemplo n.º 23
0
bool Uri::Private::parsePctEncoded()
{
    if (expectChar('%')) {
        Char curr = m_uri[m_parserPos];
        size_t currValue = curr.value();
        if (!currValue || currValue > 127 || !isHexdig[currValue]) {
            return false;
        }
        m_parserAux += curr;
        ++m_parserPos;
        curr = m_uri[m_parserPos];
        currValue = curr.value();
        if (!currValue || currValue > 127 || !isHexdig[currValue]) {
            return false;
        }
        m_parserAux += curr;
        ++m_parserPos;
    } else {
        const Char curr = m_uri[m_parserPos];
        const iuint32 currValue = curr.value();
        if (curr.octetsRequired() > 1) {
            m_parserAux += curr;
            ++m_parserPos;
        } else if (currValue && currValue < 128 && (!isUnreserved[currValue] && !isGendelim[currValue] &&
                                                    !isSubdelim[currValue] && curr != ':' && curr != '@')) {
            m_parserTrick = true;
            m_parserAux += getHex(curr);
            ++m_parserPos;
        } else {
            return false;
        }
    }
    return true;
}
Exemplo n.º 24
0
	void ByLevelUseEffect::apply(Char& target) const
	{
		if (effects.empty())
			return;

		uint16_t level = target.get_level();
		auto iter = effects.begin();
		for (; iter != effects.end() && level > iter->first; ++iter) {}
		if (iter != effects.begin())
			iter--;

		iter->second.apply(target);
	}
Exemplo n.º 25
0
void Uri::Private::parseRegName()
{
    m_parserAux.clear();
    while (true) {
        const Char curr = m_uri[m_parserPos];
        const size_t currValue = curr.value();
        if (currValue < 128 && isUnreserved[currValue]) {
            m_parserAux += curr;
            ++m_parserPos;
            continue;
        }
        const size_t parserOldPos = m_parserPos;
        if (parsePctEncoded()) {
            continue;
        }
        m_parserPos = parserOldPos;
        if (currValue < 128 && isSubdelim[currValue]) {
            m_parserAux += curr;
            ++m_parserPos;
            continue;
        }
        return;
    }
}
Exemplo n.º 26
0
TEST(VersionTest, GetVersion) {
    Int a = 3;
    Int b = any_int("B");
    Char c = 'c';

    EXPECT_EQ(0, a.get_version());
    EXPECT_EQ(0, b.get_version());
    EXPECT_EQ(0, c.get_version());

    a = b + 2 + c;

    EXPECT_EQ(1, a.get_version());
    EXPECT_EQ(0, b.get_version());
    EXPECT_EQ(0, c.get_version());

    a = 4 + b + c;

    EXPECT_EQ(2, a.get_version());
    EXPECT_EQ(0, b.get_version());
    EXPECT_EQ(0, c.get_version());

    c = a + b;

    EXPECT_EQ(2, a.get_version());
    EXPECT_EQ(0, b.get_version());
    EXPECT_EQ(1, c.get_version());

    b = 5;

    EXPECT_EQ(2, a.get_version());
    EXPECT_EQ(1, b.get_version());
    EXPECT_EQ(1, c.get_version());

    b = a;

    EXPECT_EQ(2, a.get_version());
    EXPECT_EQ(2, b.get_version());
    EXPECT_EQ(1, c.get_version());

    b = c;

    EXPECT_EQ(2, a.get_version());
    EXPECT_EQ(3, b.get_version());
    EXPECT_EQ(1, c.get_version());
}
Exemplo n.º 27
0
WindowResponse LineBuf::Insert(int y, int x, int ch) {
  WindowResponse response;
  if ((size_t)y > m_lines.size()) {
    throw ISError(string("Cannot insert ") + (char)ch + "; y out of bounds");
  } else if (m_lines.size() == (size_t)y) {
    g_log.info() << "LineBuf creating line for y=" << y;
    m_lines.push_back(new Line(y));
  } else if (m_lines.at(y).Size() == m_maxcols-2) {
    // Line too long; input ignored
    return response;
  }
  g_log.info() << "LineBuf inserting (" << y << "," << x << "):" << (char)ch;
  Char* prev = FindBefore(y, x);
  Char* next = FindAtOrAfter(y, x);
  Char* c = m_lines.at(y).Insert(x, ch);
  int x0 = x+1;
  int y0 = y;
  // Re-draw the window starting at the newly-entered character
  do {
    string s = m_lines.at(y).GetString(x);
    for (size_t i = 0; i < s.size(); ++i) {
      response.actions.push_back(WindowAction(WindowAction::INSERT, y, x + i, s[i]));
    }
    x = 0;
    ++y;
  } while ((size_t)y < m_lines.size());
  response.hotlist.Insert(c->inode);
  if (prev) {
    g_log.info() << " found before: " << *prev;
    prev->SetNext(c);
    c->SetPrevious(prev);
  }
  if (next) {
    g_log.info() << " found next: " << *next;
    next->SetPrevious(c);
    c->SetNext(next);
  }
  statik::IList* istart = &c->inode;
  while (istart->left) {
    istart = istart->left;
  }
  response.actions.push_back(WindowAction(WindowAction::MOVE, y0, x0));
  g_log.info() << "window0 olist: " << istart->Print();
  g_log.info() << "window0 hotlist: " << response.hotlist.Print();
  return response;
}
Exemplo n.º 28
0
bool Beam::charPoll( double dt ) {
    // Shifter tile bends beam
    Cell *c = g_fld->get(loc);
    if( c->gt == GT_SHIFTER && c->st == ST_NONE && c->bt == BT_AIR ) {
        Vec2 dv = dirToVec2(c->dir) * PPC* SHIFTER_ACCEL;
        v += dv * dt;
        if( v.len() > BEAM_NORMAL_VEL ) {
            v = v.normalize(BEAM_NORMAL_VEL);
        }
        setRot( atan2(v.y,v.x));
        //        print("v:%f %f  dv:%f %f d:%d",v.x,v.y, dv.x, dv.y, c->dir );
    }
    
    loc += v * dt;

    // Stronger is bigger
    float s = PPC;
    if( ene >= 64 ) s *= 3; else if( ene >= 16 ) s *= 2; else if( ene >= 4 ) s *= 1.5;
    setScl(s);
    
    // Shoot on blocks
    Vec2 rt,lt,rb,lb;
    Cell *rtc = g_fld->get( rt = loc + Vec2(hitsz,hitsz));
    Cell *ltc = g_fld->get( lt = loc + Vec2(-hitsz,hitsz));
    Cell *rbc = g_fld->get( rb = loc + Vec2(hitsz,-hitsz));
    Cell *lbc = g_fld->get( lb = loc + Vec2(-hitsz,-hitsz));
    Cell *tgtc = NULL;
    Vec2 tgtat;
    Vec2 candat[4];
    Cell *cands[4];
    int candi=0;
    // 
    if(rtc&&rtc->isBeamHit() && rtc->isImmutableAgainstBeam()==false ) { cands[candi] = rtc; candat[candi] = rt; candi++; }
    if(rbc&&rbc->isBeamHit() && rbc->isImmutableAgainstBeam()==false ) { cands[candi] = rbc; candat[candi] = rb; candi++; }
    if(ltc&&ltc->isBeamHit() && ltc->isImmutableAgainstBeam()==false ) { cands[candi] = ltc; candat[candi] = lt; candi++; }
    if(lbc&&lbc->isBeamHit() && lbc->isImmutableAgainstBeam()==false ) { cands[candi] = lbc; candat[candi] = lb; candi++; }
    if( candi > 0 ) {
        int ind = irange(0,candi);
        tgtc = cands[ind];
        tgtat = candat[ind];
    }

    // Out of the world
    if(!rtc)return false;

    if( rtc && rtc->gt == GT_JUNGLE && range(0,100) < 1 ) {
        createLeafEffect(loc);
    }

    updateIndex();

    if( isRemote() ) return true;

    if(tgtc) {
        int consumed;
        BLOCKTYPE orig_bt = tgtc->bt;
        if( g_fld->damage(tgtat,ene,&consumed,this) ) {
            createSparkEffect();
            if( orig_bt == BT_CELL || orig_bt == BT_FLYGEN ) {
                soundPlayAt(g_wormdamage_sound,loc,1);
            } else if( orig_bt != BT_SNOW && orig_bt != BT_IVY && orig_bt != BT_TREE && orig_bt != BT_BOMBFLOWER ) {
                soundPlayAt(g_beamhithard_sound,loc,1);
            }
            if( orig_bt == BT_BARRIER && tgtc->hyper_count > 0 ) {
                Vec2 tgt;
                if( g_fld->findEnemyAttackTarget(loc,&tgt, MACHINE_SHOOT_DISTANCE ) ) {
                    int n = irange(1,4);
                    for(int i=0;i<n;i++) Bullet::shootAt( BLT_SPARIO, loc, tgt );
                }
            }
            ene -= consumed;
            if( ene <= 0 ) return false; else return true;
        }
    } else {
        // Immutable cells
        Cell *cells[4];
        g_fld->getCorner4( loc, 1, &cells[0], &cells[1], &cells[2], &cells[3] );
        for(int i=0;i<4;i++) {
            if(cells[i] && cells[i]->isImmutableAgainstBeam()) {
                soundPlayAt(g_beamhithard_sound,loc,1);
                createSparkEffect();
                return false;
            }
        }
    }

    if( type == BEAMTYPE_BLASTER ) {
        float s = PPC;
        g_fld->meltSnow(loc + Vec2(-s,-s) );
        g_fld->meltSnow(loc + Vec2(-s,s) );
        g_fld->meltSnow(loc + Vec2(s,-s) );
        g_fld->meltSnow(loc + Vec2(s,s) );        
    } else {
        if( range(0,100) < (float)(ene)/2.0 ) {
            g_fld->meltSnow(loc);
        }
    }
        

    // Shoot on enemies
    Char *cur = (Char*) g_char_layer->prop_top;
    while(cur) {
        if( cur->isEnemyCategory() ) {
            Enemy *e = (Enemy*) cur;
            if( e->hitWithFlyHeight(this,PPC/2) && e->beam_hits ) {
                int dmg = ene;
                if( dmg > e->hp ) dmg = e->hp;
                e->notifyHitBeam(this, dmg);
                createSparkEffect();
                //
                ene -= dmg;
                if(ene<=0) to_clean = true;
                g_fld->meltSnow(loc);
            }
        } else if( cur->category == CAT_PC ) {
            // recharging other player characters
            PC *pc = (PC*) cur;
            if( pc->hit(this,PPC/2)) {
                //                print("pcid:%d shooter:%d ene:%d/%d", pc->id, shooter_id, pc->ene, pc->maxene );
                if( pc->id != shooter_id && shooter_id == g_pc->id ) {
                    //                    print("PC:E:%d id:%d max:%d", pc->ene, pc->id, pc->maxene );
                    int charged = pc->charge(ene);
                    if(charged>0) {
                        pc->energy_chain_heat_count ++;
                        //                        print("sending E-chain e:%d(%d>%d) to: %d-%d  heat:%d",
                        //                              ene, charged, pc->ene, pc->client_id, pc->internal_id ,pc->energy_chain_heat_count );
                        realtimeEnergyChainSend(pc,charged);
                        return false;
                    } 
                }
            }
        }
        
        cur = (Char*) cur->next;
    }




    return true;
}
Exemplo n.º 29
0
Pt::String RegexSMatch::format(const Pt::String& str) const
{
  enum state_type
  {
    state_0,
    state_esc,
    state_var0,
    state_var1,
    state_1
  } state;

  state = state_0;
  Pt::String ret;

  for (Pt::String::const_iterator it = str.begin(); it != str.end(); ++it)
  {
    Char ch = *it;

    switch (state)
    {
      case state_0:
        if (ch == '$')
          state = state_var0;
        else if (ch == '\\')
          state = state_esc;
        break;

      case state_esc:
        ret += ch;
        state = state_1;
        break;

      case state_var0:
        if( isdigit(ch) )
        {
          ret = Pt::String(str.begin(), it - 1);
            
          unsigned n = ch.value() - '0';
          if(n < _size)
          {
            const Pt::Char* s = _match->startp[n];
            const Pt::Char* e = _match->endp[n];
            assert(s && e);

            ret.append(s, e-s);
          }

            state = state_1;
        }
        else
          state = state_0;
        break;

      case state_1:
        if (ch == '$')
          state = state_var1;
        else if (ch == '\\')
          state = state_esc;
        else
          ret += ch;
        break;

      case state_var1:
        if( isdigit(ch) )
        {
          unsigned n = ch.value() - '0';

          if(n < _size)
          {
            const Pt::Char* s = _match->startp[n];
            const Pt::Char* e = _match->endp[n];
            assert(s && e);

            ret.append(s, e-s);
          }

          state = state_1;
        }
        else if (ch == '$')
          ret += '$';
        else
        {
          ret += '$';
          ret += ch;
        }
        break;
    }
  }

  switch (state)
  {
    case state_0:
    case state_var0:
      return str;

    case state_esc:
      return ret + '\\';

    case state_var1:
      return ret + '$';

    case state_1:
      return ret;
  }

  return ret;
}
Exemplo n.º 30
0
void Font::setChar(const Char& character)
{
	allCharacters[character.getId()] = character;
}