]> git.donarmstrong.com Git - lilypond.git/blob - lily/keyword.cc
* lily/spanner.cc (find_broken_piece):
[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 int tabcmp (Keyword_ent const &p1, Keyword_ent const &p2)
18 {
19   return strcmp (p1.name_, p2.name_);
20 }
21
22 Keyword_table::Keyword_table (Keyword_ent *tab)
23 {
24   while (tab->name_)
25     table_.push_back (*tab++);
26
27   vector_sort (table_, tabcmp);
28 }
29
30 vsize
31 Keyword_table::lookup (char const *s) const
32 {
33   Keyword_ent e;
34   e.name_ = s;
35   vsize idx = binary_search (table_, e, tab_less);
36   if (idx != VPOS)
37     return table_[idx].tokcode_;
38   return VPOS;
39 }