bool edit_interface_rep::complete_try () { tree st= subtree (et, path_up (tp)); if (is_compound (st)) return false; string s= st->label, ss; int end= last_item (tp); array<string> a; if (inside (LABEL) || inside (REFERENCE) || inside (PAGEREF)) { if (end != N(s)) return false; ss= copy (s); tree t= get_labels (); int i, n= N(t); for (i=0; i<n; i++) if (is_atomic (t[i]) && starts (t[i]->label, s)) a << string (t[i]->label (N(s), N(t[i]->label))); } else { if ((end==0) || (!is_iso_alpha (s[end-1])) || ((end!=N(s)) && is_iso_alpha (s[end]))) return false; int start= end-1; while ((start>0) && is_iso_alpha (s[start-1])) start--; ss= s (start, end); a= find_completions (drd, et, ss); } if (N(a) == 0) return false; complete_start (ss, a); return true; }
static void find_completions ( drd_info drd, tree t, hashset<string>& h, string prefix= "") { if (is_atomic (t)) { string s= t->label; int i= 0, n= N(s); while (i<n) { if (is_iso_alpha (s[i])) { int start= i; while ((i<n) && (is_iso_alpha (s[i]))) i++; string r= s (start, i); if (starts (r, prefix) && (r != prefix)) h->insert (r (N(prefix), N(r))); } else skip_symbol (s, i); } } else { int i, n= N(t); for (i=0; i<n; i++) if (drd->is_accessible_child (t, i)) find_completions (drd, t[i], h, prefix); } }
text_property ucs_text_language_rep::advance (tree t, int& pos) { //TODO: replace methods is_punctuation (), is_iso_alpha () and is_numeric (), // by equivalents taking into account unicode entities. string s= t->label; if (pos == N(s)) return &tp_normal_rep; if (s[pos]==' ') { pos++; // while ((pos<N(s)) && (s[pos]==' ')) pos++; if ((pos == N(s)) || (!is_punctuation (s[pos]))) return &tp_space_rep; return &tp_blank_rep; } if (is_punctuation (s[pos])) { while ((pos<N(s)) && is_punctuation (s[pos])) pos++; if ((pos==N(s)) || (s[pos]!=' ')) return &tp_normal_rep; switch (s[pos-1]) { case ',': case ':': case ';': case '`': case '\'': return &tp_space_rep; case '.': case '!': case '?': return &tp_period_rep; } return &tp_space_rep; } if (s[pos]=='-') { pos++; while ((pos<N(s)) && (s[pos]=='-')) pos++; return &tp_hyph_rep; } if (is_iso_alpha (s[pos]) || (s[pos]=='<')) { while ((pos<N(s)) && (is_iso_alpha (s[pos]) || (s[pos]=='<'))) { if (s[pos]=='<') { while ((pos<N(s)) && (s[pos]!='>')) pos++; if (pos<N(s)) pos++; } else pos++; } return &tp_normal_rep; } if (is_numeric (s[pos])) { // can not be a '.' while ((pos<N(s)) && is_numeric (s[pos])) pos++; while (s[pos-1]=='.') pos--; return &tp_normal_rep; } pos++; return &tp_normal_rep; }
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; }
text_property text_language_rep::advance (tree t, int& pos) { string s= t->label; if (pos == N(s)) return &tp_normal_rep; if (s[pos]==' ') { pos++; // while ((pos<N(s)) && (s[pos]==' ')) pos++; if ((pos == N(s)) || (!is_punctuation (s[pos]))) return &tp_space_rep; return &tp_blank_rep; } if (is_punctuation (s[pos])) { while ((pos<N(s)) && is_punctuation (s[pos])) pos++; if ((pos==N(s)) || (s[pos]!=' ')) return &tp_normal_rep; switch (s[pos-1]) { case ',': case ':': case ';': case '`': case '\'': return &tp_space_rep; case '.': case '!': case '?': return &tp_period_rep; } return &tp_space_rep; } if (s[pos]=='-') { pos++; while ((pos<N(s)) && (s[pos]=='-')) pos++; return &tp_hyph_rep; } if (is_iso_alpha (s[pos])) { while ((pos<N(s)) && is_iso_alpha (s[pos])) pos++; return &tp_normal_rep; } if (is_numeric (s[pos])) { // can not be a '.' while ((pos<N(s)) && is_numeric (s[pos])) pos++; while (s[pos-1]=='.') pos--; return &tp_normal_rep; } if (s[pos]=='<') { while ((pos<N(s)) && (s[pos]!='>')) pos++; if (pos<N(s)) pos++; return &tp_normal_rep; } pos++; return &tp_normal_rep; }
static int breaking_force (char c) { if (c == ' ') return 3; if (is_punctuation (c)) return 2; if (is_iso_alpha (c) || is_digit (c)) return 0; return 1; }
static void adjust_left_script (tree t, path& o2) { while (is_concat (t) && o2->item + 1 < N(t) && o2->next == path (1)) { tree st= t[o2->item]; if (is_func (st, LSUB) || is_func (st, LSUP) || is_func (st, LPRIME)) { tree nt= t[o2->item+1]; if (!is_atomic (nt)) o2= path (o2->item+1, end (nt)); else { string s= nt->label; int pos= 0; while (pos < N(s)) { int next= pos; tm_char_forwards (s, next); if (pos == 0); else if (is_numeric (s (0, next))); else if (is_iso_alpha (s (0, next))); else break; pos= next; } o2= path (o2->item+1, pos); } } else break; } }
static void adjust_right_script (tree t, path& o1) { while (is_concat (t) && o1->item > 0 && o1->next == path (0)) { tree st= t[o1->item]; if (is_func (st, RSUB) || is_func (st, RSUP) || is_func (st, RPRIME)) { tree pt= t[o1->item-1]; if (!is_atomic (pt)) o1= path (o1->item-1, start (pt)); else { string s= pt->label; int pos= N(s); while (pos > 0) { int prev= pos; tm_char_backwards (s, prev); if (pos == N(s)); else if (is_numeric (s (prev, N(s)))); else if (is_iso_alpha (s (prev, N(s)))); else break; pos= prev; } o1= path (o1->item-1, pos); } } else break; } }
tree evaluate_change_case (tree t, tree nc, bool evaluate_flag, bool first) { if (is_atomic (t)) { string s= t->label; tree r= copy (s); int i, n= N(s); bool all= true; bool up = false; bool lo = false; if (nc == "Upcase") { all= false; up= true; } else if (nc == "UPCASE") { up= true; } else if (nc == "locase") { lo= true; } for (i=0; i<n; tm_char_forwards (s, i)) if (is_iso_alpha (s[i]) && (all || (first && (i==0)))) { if (up && is_locase (s[i])) r->label[i]= upcase (s[i]); if (lo && is_upcase (s[i])) r->label[i]= locase (s[i]); } r->obs= list_observer (ip_observer (obtain_ip (t)), r->obs); return r; } else if (is_concat (t)) { int i, n= N(t); tree r (t, n); for (i=0; i<n; i++) r[i]= evaluate_change_case (t[i], nc, evaluate_flag, first && (i==0)); r->obs= list_observer (ip_observer (obtain_ip (t)), r->obs); return r; } else { if (evaluate_flag) return t; else return evaluate_change_case (evaluate (t), nc, true, first); } }
static string index_name_sub (tree t, bool all) { if (is_atomic (t)) { string s= t->label, r; int i, n= N(s); for (i=0; i<n; i++) if (is_iso_alpha (s[i]) || is_digit (s[i]) || (s[i] == ' ') || (all && (s[i] >= ' '))) r << s[i]; return r; } else if (is_concat (t)) { string r; int i, n= N(t); for (i=0; i<n; i++) r << index_name_sub (t[i], all); return r; } else if (is_tuple (t)) { string r; int i, j, n= N(t); for (i=0; i<n; i++) { if (i!=0) r << "\t"; string s= index_name_sub (t[i], false); if (s == "") s= index_name_sub (t[i], true); tree u= copy (followup [s]); for (j=0; j<N(u); j++) if (u[j] == t[i]) break; if (j == N(u)) { u << t[i]; followup (s)= u; } r << s; if (j != 0) r << "\n" << as_string (j); } return r; } else if (all && is_func (t, WITH)) return index_name_sub (t[N(t)-1], all); else return ""; }