]> git.lyx.org Git - lyx.git/blob - src/support/counter_reps.cpp
Limit the nopassthurchars case in beamer to URL
[lyx.git] / src / support / counter_reps.cpp
1 /**
2  * \file convert.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "support/counter_reps.h"
15
16 #include "support/convert.h"
17 #include "support/docstring.h"
18 #include "support/lstrings.h"
19
20 using namespace std;
21
22 namespace lyx {
23
24 char loweralphaCounter(int const n)
25 {
26     if (n < 1 || n > 26)
27         return '?';
28     return 'a' + n - 1;
29 }
30
31
32 char alphaCounter(int const n)
33 {
34     if (n < 1 || n > 26)
35            return '?';
36     return 'A' + n - 1;
37 }
38
39
40 char hebrewCounter(int const n)
41 {
42     static const char hebrew[22] = {
43         '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7', '\xe8',
44         '\xe9', '\xeb', '\xec', '\xee', '\xf0', '\xf1', '\xf2', '\xf4', '\xf6',
45         '\xf7', '\xf8', '\xf9', '\xfa'
46     };
47
48     if (n < 1 || n > 22)
49         return '?';
50     return hebrew[n - 1];
51 }
52
53
54 // On the special cases, see http://mathworld.wolfram.com/RomanNumerals.html
55 // and for a list of roman numerals up to and including 3999, see
56 // http://www.research.att.com/~njas/sequences/a006968.txt. (Thanks to Joost
57 // for this info.)
58 docstring const romanCounter(int const n)
59 {
60     static char const * const ones[9] = {
61         "I",   "II",  "III", "IV", "V",
62         "VI",  "VII", "VIII", "IX"
63     };
64
65     static char const * const tens[9] = {
66         "X", "XX", "XXX", "XL", "L",
67         "LX", "LXX", "LXXX", "XC"
68     };
69
70     static char const * const hunds[9] = {
71         "C", "CC", "CCC", "CD", "D",
72         "DC", "DCC", "DCCC", "CM"
73     };
74
75     if (n >= 1000 || n < 1)
76           return from_ascii("??");
77
78     int val = n;
79     string roman;
80     switch (n) {
81     //special cases
82     case 900:
83         roman = "CM";
84         break;
85     case 400:
86         roman = "CD";
87         break;
88     default:
89         if (val >= 100) {
90                 int hundreds = val / 100;
91                 roman = hunds[hundreds - 1];
92                 val = val % 100;
93         }
94         if (val >= 10) {
95             switch (val) {
96             //special case
97             case 90:
98                 roman = roman + "XC";
99                 val = 0; //skip next
100                 break;
101             default:
102                 int tensnum = val / 10;
103                 roman = roman + tens[tensnum - 1];
104                 val = val % 10;
105             } // end switch
106         } // end tens
107         if (val > 0)
108              roman = roman + ones[val -1];
109     }
110     return from_ascii(roman);
111 }
112
113
114 docstring const lowerromanCounter(int const n)
115 {
116         return support::lowercase(romanCounter(n));
117 }
118
119
120 docstring const fnsymbolCounter(int const n)
121 {
122         switch(n) {
123         case 1: return docstring(1, 0x002a); //*
124         case 2: return docstring(1, 0x2020); // dagger
125         case 3: return docstring(1, 0x2021); // double dagger
126         case 4: return docstring(1, 0x00A7); // section sign
127         case 5: return docstring(1, 0x00B6); // pilcrow sign
128         case 6: return docstring(1, 0x2016); // vertical bar
129         case 7: return docstring(2, 0x002a); // two *
130         case 8: return docstring(2, 0x2020); // two daggers
131         case 9: return docstring(2, 0x2021); // two double daggers
132         default:
133                 return from_ascii("?");
134         };
135 }
136
137
138 docstring const superarabicCounter(int const n)
139 {
140         docstring superarabic = convert<docstring>(n);
141         static char_type map[] = {0x2070, 0x00b9, 0x00b2, 0x00b3, 0x2074,
142                                   0x2075, 0x2076, 0x2077, 0x2078, 0x2079 };
143         for (char_type & c : superarabic)
144                 c = map[c - char_type('0')];
145         return superarabic;
146 }
147
148 } // namespace lyx