Esempio n. 1
0
string
dictionary_rep::translate (string s, bool guess) {
  if (s == "" || from == to) return s;
  //cout << "Translate <" << s << ">\n";
  // Is s in dictionary?
  if (table->contains (s) && table[s] != "")
    return table[s];
  
  // Is lowercase version of s in dictionary?
  string ls= locase_first (s);
  if (table->contains (ls) && table[ls] != "")
    return upcase_first (table[ls]);
  
  // Attempt to split the string and translate its parts?
  if (!guess) return s;
  
  // Remove trailing non iso_alpha characters
  int i, n= N(s);
  for (i=0; i<n; i++)
    if (is_iso_alpha (s[i]))
      break;
  int start= i;
  for (i=n; i>0; i--)
    if (is_iso_alpha (s[i-1]))
      break;
  int end= i;
  if (start >= n || end <= 0) return s;
  if (start != 0 || end != n) {
    ASSERT (start < end, "invalid situation");
    string s1= translate (s (0, start));
    string s2= translate (s (start, end));
    string s3= translate (s (end, n));
    if (to == "french") {
      if (s3 == ":") s3= " :";
      if (s3 == "!") s3= " !";
      if (s3 == "?") s3= " ?";
    }
    return s1 * s2 * s3;
  }

  // Break at last non iso_alpha character which is not a space
  for (i=n; i>0; i--)
    if (!is_iso_alpha (s[i-1]) && s[i-1] != ' ')
      break;
  if (i > 0) {
    string s1= translate (s (0, i));
    string s2= translate (s (i, n));
    return s1 * s2;
  }

  // No translation available
  return s;
}
Esempio n. 2
0
static void
add_greek (string sym) {
  locase_tab ("<" * upcase_first (sym) * ">")= "<" * sym * ">";
  upcase_tab ("<" * sym * ">")= "<" * upcase_first (sym) * ">";
  upcase_tab ("<var" * sym * ">")= "<" * upcase_first (sym) * ">";
}