]> git.donarmstrong.com Git - lilypond.git/blob - lily/keyword.cc
Web-ja: update introduction
[lilypond.git] / lily / keyword.cc
1 /*
2   keyword.cc -- keywords and identifiers
3 */
4
5 #include "keyword.hh"
6
7 #include <cstring>
8 #include <cstdlib>
9 using namespace std;
10
11 /* for qsort */
12 bool tab_less (Keyword_ent const &p1, Keyword_ent const &p2)
13 {
14   return strcmp (p1.name_, p2.name_) < 0;
15 }
16
17 Keyword_table::Keyword_table (Keyword_ent *tab)
18 {
19   while (tab->name_)
20     table_.push_back (*tab++);
21
22   vector_sort (table_, tab_less);
23 }
24
25 vsize
26 Keyword_table::lookup (char const *s) const
27 {
28   Keyword_ent e;
29   e.name_ = s;
30   vsize idx = binary_search (table_, e, tab_less);
31   if (idx != VPOS)
32     return table_[idx].tokcode_;
33   return VPOS;
34 }