Example #1
0
string trimmedName(string& s)
{
    //printf("splitting %s\n",s.c_str());
    StrVec vec;
    int n=strsplit_slash(s, vec);

    //for(int i=0;i<n;i++) printf("  '%s'\n",vec[i].c_str());

    unsigned int i=0;
    while(i<vec.size())
    {
        if(i>0)
        {
            if(vec[i]==".." && vec[i-1]!="..")
            {
                i--;
                vec.erase(vec.begin()+i,vec.begin()+i+2);
                continue;
            }
        }

        i++;
    }
    if(!vec.size()) return "";
    string ret="";
    for(unsigned int i=0; i<vec.size(); i++)
    {
        ret+=vec[i];
        if(i+1!=vec.size()) ret+="/";
    }
    return ret;
}
Example #2
0
File: SLData.cpp Project: clagv/sl
 bool Data::erase(const std::string& key, size_t keyIdx)
 {
     if(keyIdx < m_keyIdx.size())
     {
         KeyIdx ki(key, 0);
         size_t pos = (std::lower_bound(m_keyIdx.begin(), m_keyIdx.end(), ki, key_less) - m_keyIdx.begin()) + keyIdx;
         if(pos < m_keyIdx.size() && key_eql(ki, m_keyIdx[pos]))
         {
             // users shouldn't really erase keys while reading data but ...
             if(m_pos < m_keyIdx.size() && m_pos > pos)
                 --m_pos;
             m_keyIdx.erase(m_keyIdx.begin() + pos);
             m_keys.erase(m_keys.begin() + pos);
             m_varData.erase(m_varData.begin() + pos);
             return true;
         }
     }
     return false;
 }