📄 alphabet.h
字号:
/* * ASTL - the Automaton Standard Template Library. * C++ generic components for Finite State Automata handling. * Copyright (C) 2000-2003 Vincent Le Maout (vincent.lemaout@chello.fr). * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */#ifndef ASTL_ALPHABET_H#define ASTL_ALPHABET_H// This file implements four alphabet traits:// 1. template <class T, T lower_bound, T upper_bound> range// 2. plain// 3. ASCII// 4. french#include <astl.h>#include <iterator>#include <string>ASTL_BEGIN_NAMESPACEusing namespace std;#if (__GNUG__ && __GNUG__ < 3)#define CHAR_TRAITS string_char_traits#else#define CHAR_TRAITS char_traits#endiftemplate <typename T, T lower_bound, T upper_bound>class range : public CHAR_TRAITS<T>{public: typedef typename CHAR_TRAITS<T>::char_type char_type; typedef long int_type; static const size_t size; static char_type to_char_type(int_type e) { return (char_type) (e + lower_bound); } static int_type to_int_type(char_type c) { return (int_type) c - lower_bound; } static bool eq_int_type(int_type x, int_type y) { return x == y; }#if (__GNUG__ && __GNUG__ < 3) class const_iterator : public bidirectional_iterator<T, ptrdiff_t>#else class const_iterator : public std::iterator<std::bidirectional_iterator_tag, T>#endif { private: int_type c; public: const_iterator() { } const_iterator(int_type x) : c(x) { } const_iterator& operator++ () { ++c; return (*this); } const_iterator operator++ (int) { const_iterator tmp = *this; ++(*this); return (tmp); } char_type operator* () const { return (char_type) c; } bool operator== (const const_iterator& i) const { return c == i.c; } bool operator!= (const const_iterator& i) const { return !(*this == i); } }; static const_iterator begin() { return const_iterator(lower_bound); } static const_iterator end() { return const_iterator(upper_bound + 1); } // These are not standard requirements (backward compatibility purpose): typedef const_iterator iterator; typedef char_type Alphabet; static unsigned long map(const char_type &x) { return (unsigned long) to_int_type(x); } static char_type unmap(unsigned long x) { return to_char_type((int_type) x); }};#ifndef _MSC_VERtemplate <typename T, T lower_bound, T upper_bound> const size_trange<T, lower_bound, upper_bound>::size = (size_t) upper_bound - lower_bound + 1;#endiftypedef range<char, (char) -128, (char) 127> plain;typedef range<char, (char) 0, (char) 127> ASCII;#ifdef _MSC_VER// VC++ 6.0 does not compile the previous generic 'size' initialization:const size_t plain::size = 256;const size_t ASCII::size = 128;#endif#ifndef _MSC_VERclass french : public CHAR_TRAITS<char>{public: typedef char int_type; static const size_t size; // mapping table from chars to integral value: static const int_type c2i[256]; // mapping table from integral value to chars: static const char i2c[65]; static char_type to_char_type(int_type e) { return i2c[e]; } static int_type to_int_type(char_type c) { return c2i[c]; } static bool eq_int_type(int_type x, int_type y) { return x == y; }#if (__GNUG__ && __GNUG__ < 3) class const_iterator : public bidirectional_iterator<char, ptrdiff_t>#else class const_iterator : public std::iterator<std::bidirectional_iterator_tag, char>#endif { private: int_type c; public: const_iterator() { } const_iterator(int_type x) : c(x) { } const_iterator& operator++ () { ++c; return (*this); } const_iterator operator++ (int) { const_iterator tmp = *this; ++(*this); return (tmp); } char_type operator* () const { return french::to_char_type(c); } bool operator== (const const_iterator& i) const { return c == i.c; } bool operator!= (const const_iterator& i) const { return !(*this == i); } }; static const_iterator begin() { return const_iterator(0); } static const_iterator end() { return const_iterator(size); } // These are not standard requirements (backward compatibility purpose): typedef const_iterator iterator; typedef char_type Alphabet; static unsigned long map(const char_type &x) { return (unsigned long) to_int_type(x); } static char_type unmap(unsigned long x) { return to_char_type((int_type) x); }};const size_t french::size = 65;const french::int_type french::c2i[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 52, 0, 53, 0, 0, 0, 0, 54, 55, 56, 57, 58, 0, 0, 59, 60, 0, 0, 0, 0, 61, 0, 0, 0, 0, 62, 0, 63, 64, 0, 0, 0 };const char french::i2c[65] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -