1 /*
2 ** Copyright 2003-2004, Double Precision Inc.
3 **
4 ** See COPYING for distribution information.
5 */
6 
7 #ifndef cursesmoronize_H
8 #define cursesmoronize_H
9 
10 #include "mycurses.H"
11 
12 ///////////////////////////////////////////////////////////////////////////
13 //
14 // "Smart characters" processing, a.k.a. moronization
15 // Example:  Convert typed "1/4" to the ISO-8859-1 character for 1/4.
16 //
17 
18 class CursesMoronize {
19 
20 public:
21 
22 
23 	static size_t moronize(const char32_t *buf,
24 			       std::u32string &nreplaced);
25 	//
26 	// 'buf' should be the characters just preceding the current cursor
27 	// position, IN REVERSE ORDER.  So, if the cursor is now:
28 	//
29 	//           ...1/4_       _ marks the cursor position
30 	//
31 	// ... then 'buf' should be '4/1...'.  buf can be as long as the
32 	// caller wants.  We search for a suitable replacement using
33 	// strncmp
34 	//
35 	// If found a replacement, returns non-zero chars to replace, and
36 	// set nreplaced to the replacement character
37 
38 	class Entry {
39 	public:
40 		const char32_t *keycode;
41 		size_t keycodeLen;
42 		const char32_t *replacements;
43 	};
44 
45 	static bool enabled;
46 	static Entry moronizationList[];
47 
48 	static const int max_keycode_len=5;
49 
50 };
51 
52 #endif
53