File: WordGeneratorBase.cpp

package info (click to toggle)
dasher 4.11%2Bgit20130508.adc653-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 40,248 kB
  • ctags: 5,158
  • sloc: xml: 185,479; cpp: 32,301; sh: 11,207; makefile: 828; ansic: 483
file content (34 lines) | stat: -rw-r--r-- 1,100 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "WordGeneratorBase.h"

using namespace Dasher;

CWordGeneratorBase::CWordGeneratorBase(const CAlphInfo *pAlph, const CAlphabetMap *pAlphMap) : m_pAlph(pAlph), m_pAlphMap(pAlphMap) {
}

void CWordGeneratorBase::GetSymbols(std::vector<symbol> &into) {
  for (;;) {
    string s(GetLine());
    if (s.empty()) break; //no more lines, so no more symbols...
    stringstream line(s);
    CAlphabetMap::SymbolStream ss(line);
    for (int sym; (sym=ss.next(m_pAlphMap))!=-1; ) {
      if (!into.empty()) {
        const symbol lastSym(into.back());
        if (sym==0 && lastSym == m_pAlph->GetSpaceSymbol()) continue; //skip unknown after space
        if (lastSym==0) {
          //convert last sym to a space, or combine with next sym
          into.pop_back();
          if (sym!=0 && sym!=m_pAlph->GetSpaceSymbol()) 
            into.push_back(m_pAlph->GetSpaceSymbol());
        }
      }
      into.push_back(sym);
    }
    if (!into.empty()) {
      if (into.back()==0) into.pop_back();
      if (!into.empty()) break;
    }
    //didn't find any usable symbols in line! repeat...
  }
}