Back to index

texmacs  1.0.7.15
Functions
hyphenate.hpp File Reference
#include "language.hpp"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void load_hyphen_tables (string language_name, hashmap< string, string > &patterns, hashmap< string, string > &hyphenations)
array< int > get_hyphens (string s, hashmap< string, string > patterns, hashmap< string, string > hyphenations)
void std_hyphenate (string s, int after, string &left, string &right, int pen)

Function Documentation

array<int> get_hyphens ( string  s,
hashmap< string, string patterns,
hashmap< string, string hyphenations 
)

Definition at line 109 of file hyphenate.cpp.

                                                  {
  ASSERT (N(s) != 0, "hyphenation of empty string");

  if (hyphenations->contains (s)) {
    string h= hyphenations [s];
    array<int> penalty (N(s)-1);
    int i=0, j=0;
    while (h[j] == '-') j++;
    i++; j++;
    while (i < N(s)) {
      penalty[i-1]= HYPH_INVALID;
      while (j < N(h) && h[j] == '-') {
        penalty[i-1]= HYPH_STD;
        j++;
      }
      i++; j++;
    }
    //cout << s << " --> " << penalty << "\n";
    return penalty;
  }
  else {
    s= "." * lower_case (s) * ".";
    // cout << s << "\n";
    int i, j, k, m, len;
    array<int> T (N(s)+1);
    for (i=0; i<N(s)+1; i++) T[i]=0;
    for (len=1; len < MAX_SEARCH; len++)
      for (i=0; i<N(s)-len; i++) {
        string r= patterns [s (i, i+len)];
        if (!(r == "?")) {
          // cout << "  " << s (i, i+len) << " => " << r << "\n";
          for (j=0, k=0; j<=len; j++, k++) {
            if ((k<N(r)) && (r[k]>='0') && (r[k]<='9')) {
              m=((int) r[k])-((int) '0');
              k++;
            }
            else m=0;
            if (m>T[i+j]) T[i+j]=m;
          }
        }
      }

    array<int> penalty (N(s)-3);
    for (i=2; i<N(s)-1; i++)
      penalty [i-2]= (((T[i]&1)==1)? HYPH_STD: HYPH_INVALID);
    if (N(penalty)>0) penalty[0] = penalty[N(penalty)-1] = HYPH_INVALID;
    if (N(penalty)>1) penalty[1] = penalty[N(penalty)-2] = HYPH_INVALID;
    if (N(penalty)>2) penalty[N(penalty)-3] = HYPH_INVALID;
    // cout << s << " --> " << penalty << "\n";
    return penalty;
  }
}

Here is the call graph for this function:

void load_hyphen_tables ( string  language_name,
hashmap< string, string > &  patterns,
hashmap< string, string > &  hyphenations 
)

Definition at line 58 of file hyphenate.cpp.

                                                          {
  string s;
  file_name= string ("hyphen.") * file_name;
  load_string (url ("$TEXMACS_PATH/langs/natural/hyphen", file_name), s, true);
  if (DEBUG_VERBOSE) cout << "TeXmacs] Loading " << file_name << "\n";

  hashmap<string,string> H ("?");
  bool pattern_flag=false;
  bool hyphenation_flag=false;
  int i=0, n= N(s);
  while (i<n) {
    string buffer;
    while ((i<n) && (s[i]!=' ') && (s[i]!='\t') && (s[i]!='\n')) {
      if (s[i] != '%') buffer << s[i++];
      else while ((i<n) && (s[i]!='\n')) i++;
    }
    if (i<n) i++;
    if (buffer == "}") {
      pattern_flag=false;
      hyphenation_flag=false;
    }
    if (pattern_flag && i != 0) {
      string norm= hyphen_normalize (buffer);
      patterns (unpattern (norm))= norm;
      //cout << unpattern (norm) << " ==> " << norm << "\n";
    }
    if (hyphenation_flag && i != 0 && N(buffer) != 0) {
      string word= replace (buffer, "-", "");
      hyphenations (word)= buffer;
      //cout << word << " --> " << buffer << "\n";
    }
    if (buffer == "\\patterns{") pattern_flag=true;
    if (buffer == "\\hyphenation{") hyphenation_flag=true;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void std_hyphenate ( string  s,
int  after,
string left,
string right,
int  pen 
)

Definition at line 165 of file hyphenate.cpp.

                                                                              {
  left = s (0, after+1);
  right= s (after+1, N(s));
  if (penalty >= HYPH_INVALID) left << string ("\\");
  else left << string ("-");
}

Here is the call graph for this function:

Here is the caller graph for this function: