/usr/include/sp/CharMap.cxx is in libsp1-dev 1.3.4-1.2.1-47.3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | // Copyright (c) 1997 James Clark
// See the file COPYING for copying permission.
#ifndef CharMap_DEF_INCLUDED
#define CharMap_DEF_INCLUDED 1
#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif
#ifdef SP_MULTI_BYTE
template<class T>
CharMap<T>::CharMap()
{
}
template<class T>
CharMap<T>::CharMap(T dflt)
{
for (size_t i = 0; i < (1 << CharMapBits::level1); i++)
pages_[i].value = dflt;
}
template<class T>
void CharMap<T>::setAll(T val)
{
for (size_t i = 0; i < (1 << CharMapBits::level1); i++) {
pages_[i].value = val;
delete [] pages_[i].values;
pages_[i].values = 0;
}
}
template<class T>
void CharMap<T>::swap(CharMap<T> &map)
{
for (size_t i = 0; i < (1 << CharMapBits::level1); i++)
pages_[i].swap(map.pages_[i]);
}
template<class T>
void CharMap<T>::setChar(Char c, T val)
{
CharMapPage<T> &pg = pages_[c >> (CharMapBits::level2 + CharMapBits::level3)];
if (pg.values) {
CharMapColumn<T> &column = pg.values[(c >> CharMapBits::level3) & ((1 << CharMapBits::level2) - 1)];
if (column.values)
column.values[c & ((1 << CharMapBits::level3) - 1)] = val;
else if (val != column.value) {
column.values = new T[1 << CharMapBits::level3];
for (size_t i = 0; i < (1 << CharMapBits::level3); i++)
column.values[i] = column.value;
column.values[c & ((1 << CharMapBits::level3) - 1)] = val;
}
}
else if (val != pg.value) {
pg.values = new CharMapColumn<T>[1 << CharMapBits::level2];
for (size_t i = 0; i < (1 << CharMapBits::level2); i++)
pg.values[i].value = pg.value;
CharMapColumn<T> &column = pg.values[(c >> CharMapBits::level3) & ((1 << CharMapBits::level2) - 1)];
column.values = new T[1 << CharMapBits::level3];
for (size_t i = 0; i < (1 << CharMapBits::level3); i++)
column.values[i] = column.value;
column.values[c & ((1 << CharMapBits::level3) - 1)] = val;
}
}
template<class T>
void CharMap<T>::setRange(Char from, Char to, T val)
{
do {
if ((from & ((1 << CharMapBits::level3) - 1)) == 0
&& to - from >= (1 << CharMapBits::level3) - 1) {
if ((from & ((1 << (CharMapBits::level2 + CharMapBits::level3)) - 1)) == 0
&& to - from >= (1 << (CharMapBits::level2 + CharMapBits::level3)) - 1) {
// Set a complete page.
CharMapPage<T> &pg = pages_[from >> (CharMapBits::level2 + CharMapBits::level3)];
pg.value = val;
delete [] pg.values;
pg.values = 0;
from += (1 << (CharMapBits::level2 + CharMapBits::level3)) - 1;
}
else {
// Set a complete column.
CharMapPage<T> &pg = pages_[from >> (CharMapBits::level2 + CharMapBits::level3)];
if (pg.values) {
CharMapColumn<T> &column = pg.values[(from >> CharMapBits::level3) & ((1 << CharMapBits::level2) - 1)];
column.value = val;
delete [] column.values;
column.values = 0;
}
else if (val != pg.value) {
// split the page
pg.values = new CharMapColumn<T>[1 << CharMapBits::level2];
for (size_t i = 0; i < (1 << CharMapBits::level2); i++)
pg.values[i].value = pg.value;
CharMapColumn<T> &column = pg.values[(from >> CharMapBits::level3) & ((1 << CharMapBits::level2) - 1)];
column.value = val;
}
from += (1 << CharMapBits::level2) - 1;
}
}
else
setChar(from, val);
} while (from++ != to);
}
template<class T>
CharMapPage<T>::CharMapPage()
: values(0)
{
}
template<class T>
CharMapPage<T>::CharMapPage(const CharMapPage<T> &pg)
{
if (pg.values) {
values = new CharMapColumn<T>[1 << CharMapBits::level2];
for (size_t i = 0; i < (1 << CharMapBits::level2); i++)
values[i] = pg.values[i];
}
else {
value = pg.value;
values = 0;
}
}
template<class T>
void CharMapPage<T>::operator=(const CharMapPage<T> &pg)
{
if (pg.values) {
if (!values)
values = new CharMapColumn<T>[1 << CharMapBits::level2];
for (size_t i = 0; i < (1 << CharMapBits::level2); i++)
values[i] = pg.values[i];
}
else {
if (values) {
delete [] values;
values = 0;
}
value = pg.value;
}
}
template<class T>
CharMapPage<T>::~CharMapPage()
{
delete [] values;
}
template<class T>
void CharMapPage<T>::swap(CharMapPage<T> &pg)
{
{
CharMapColumn<T> *tem = values;
values = pg.values;
pg.values = tem;
}
{
T tem(value);
value = pg.value;
pg.value = tem;
}
}
template<class T>
CharMapColumn<T>::CharMapColumn()
: values(0)
{
}
template<class T>
CharMapColumn<T>::CharMapColumn(const CharMapColumn<T> &col)
{
if (col.values) {
values = new T[1 << CharMapBits::level3];
for (size_t i = 0; i < (1 << CharMapBits::level3); i++)
values[i] = col.values[i];
}
else {
values = 0;
value = col.value;
}
}
template<class T>
void CharMapColumn<T>::operator=(const CharMapColumn<T> &col)
{
if (col.values) {
if (!values)
values = new T[1 << CharMapBits::level3];
for (size_t i = 0; i < (1 << CharMapBits::level3); i++)
values[i] = col.values[i];
}
else {
if (values) {
delete [] values;
values = 0;
}
value = col.value;
}
}
template<class T>
CharMapColumn<T>::~CharMapColumn()
{
delete [] values;
}
#else /* not SP_MULTI_BYTE */
template<class T>
CharMap<T>::CharMap()
{
}
template<class T>
CharMap<T>::CharMap(T dflt)
{
for (int i = 0; i < 256; i++)
values_[i] = dflt;
}
template<class T>
void CharMap<T>::setAll(T val)
{
for (size_t i = 0; i < 256; i++)
values_[i] = val;
}
template<class T>
void CharMap<T>::setRange(Char from, Char to, T val)
{
do {
values_[from] = val;
} while (from++ != to);
}
template<class T>
void CharMap<T>::swap(CharMap<T> &map)
{
for (size_t i = 0; i < 256; i++) {
T tem(values_[i]);
values_[i] = map.values_[i];
map.values_[i] = tem;
}
}
#endif /* not SP_MULTI_BYTE */
#ifdef SP_NAMESPACE
}
#endif
#endif /* not CharMap_DEF_INCLUDED */
|