Logo Search packages:      
Sourcecode: apertium version File versions  Download package

void TransferWord::assign ( map< char const *, pair< int, int > > &  m,
string &  str,
char const *  part,
string const &  value 
) [private]

Assings a value to the source/target side of a word using the specified part

Parameters:
m tipically s or t
str tipically s_str or t_str
part regular expression to match/access the string to be assigned

Definition at line 149 of file TransferWord.C.

References getRegex().

{
  map<char const *, pair<int, int> >::iterator it = m.find(part);

  if(it == m.end())
  {
    regmatch_t result;
    int errorcode = regexec(&(getRegex(part)), str.c_str(), 1, &result, 0);
    if(errorcode != 0)
    {
      return;
    }
    m[part] = pair<int, int>(result.rm_so, result.rm_eo);
  }

  string newstr = str.substr(0, m[part].first);
  newstr.append(value);
  newstr.append(str.substr(m[part].second));
  str = newstr;

  int dif = value.size() - (m[part].second - m[part].first);
  int const lowlimit = m[part].first;
  int const uplimit = m[part].second;
  for(it = m.begin(); it != m.end(); it++)
  {
    if(it->second.first >= uplimit)
    {
      it->second.first += dif;
      it->second.second += dif;
    } 
    else if(it->second.first > lowlimit)
    {
      // invalidate overlapping patterns
      m.erase(it);
    }
    else if(it->second.second >= uplimit)
    {
      it->second.second += dif;
    }
    else if(it->second.second > lowlimit)
    {
      // invalidate overlapping patterns
      m.erase(it);
    }
  }
}


Generated by  Doxygen 1.6.0   Back to index