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