xref: /trunk/main/autodoc/inc/cosv/str_types.hxx (revision 11c03c6d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef COSV_STR_TYPES_HXX
25 #define COSV_STR_TYPES_HXX
26 
27 
28 namespace csv
29 {
30 
31 /** Provides some generally used constants.
32 */
33 struct str
34 {
35   public:
36     typedef ::size_t    position;
37     typedef ::size_t    size;
38 
39     enum constants
40     {
41         npos = position(-1),
42         maxsize = size(-1)
43     };
44 
45     enum insert_mode
46     {
47         overwrite = 0,
48         insert = 1
49     };
50 };
51 
52 
53 /** Is used for string comparisons.
54 
55     @collab String
56     @collab various csv::compare(...) functions
57 */
58 class CharOrder_Table
59 {
60   public:
61     /** @precond
62         Parameter i_pCharWeightsArray
63         must have size of 256.
64     */
65                         CharOrder_Table(
66                             const int *         i_pCharWeightsArray );
67 
68     /** @return the weight of the char i_c.
69         @precond
70         Even with unusual implementations, where char has more than 8 bit,
71         there must be true: 0 <= i_c < 256.
72     */
73     int                 operator()(
74                             char                i_c ) const;
75   private:
76     int                 cWeights[256];
77 };
78 
79 
80 // IMPLEMENTATION
81 
82 inline int
operator ()(char i_c) const83 CharOrder_Table::operator()( char i_c ) const
84     { return cWeights[ UINT8(i_c) ]; }
85 
86 
87 
88 }   // namespace csv
89 
90 #endif
91