1d25dac7peter/* svn_token.h : value/string-token functions
2d25dac7peter *
3d25dac7peter * ====================================================================
4d25dac7peter *    Licensed to the Apache Software Foundation (ASF) under one
5d25dac7peter *    or more contributor license agreements.  See the NOTICE file
6d25dac7peter *    distributed with this work for additional information
7d25dac7peter *    regarding copyright ownership.  The ASF licenses this file
8d25dac7peter *    to you under the Apache License, Version 2.0 (the
9d25dac7peter *    "License"); you may not use this file except in compliance
10d25dac7peter *    with the License.  You may obtain a copy of the License at
11d25dac7peter *
12d25dac7peter *      http://www.apache.org/licenses/LICENSE-2.0
13d25dac7peter *
14d25dac7peter *    Unless required by applicable law or agreed to in writing,
15d25dac7peter *    software distributed under the License is distributed on an
16d25dac7peter *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17d25dac7peter *    KIND, either express or implied.  See the License for the
18d25dac7peter *    specific language governing permissions and limitations
19d25dac7peter *    under the License.
20d25dac7peter * ====================================================================
21d25dac7peter */
22d25dac7peter
23d25dac7peter#ifndef SVN_TOKEN_H
24d25dac7peter#define SVN_TOKEN_H
25d25dac7peter
26d25dac7peter
27d25dac7peter#include "svn_error.h"
28d25dac7peter
29d25dac7peter
30d25dac7peter#ifdef __cplusplus
31d25dac7peterextern "C" {
32d25dac7peter#endif /* __cplusplus */
33d25dac7peter
34d25dac7peter
35d25dac7peter/** A mapping between a string STR and an enumeration value VAL.
36d25dac7peter *
37d25dac7peter * Maps are an array of these, terminated with a struct where STR == NULL.
38d25dac7peter */
39d25dac7petertypedef struct svn_token_map_t
40d25dac7peter{
41d25dac7peter  const char *str;
42d25dac7peter  int val;
43d25dac7peter} svn_token_map_t;
44d25dac7peter
45d25dac7peter
46d25dac7peter/* A value used by some token functions to indicate an unrecognized token.  */
47d25dac7peter#define SVN_TOKEN_UNKNOWN (-9999)
48d25dac7peter
49d25dac7peter
50d25dac7peter/* Return the string form of the given VALUE as found in MAP. If the value
51d25dac7peter   is not recognized, then a MALFUNCTION will occur.  */
52d25dac7peterconst char *
53d25dac7petersvn_token__to_word(const svn_token_map_t *map,
54d25dac7peter                   int value);
55d25dac7peter
56d25dac7peter
57d25dac7peter/* NOTE: in the following functions, if WORD is NULL, then SVN_TOKEN_UNKNOWN
58d25dac7peter   will be returned, or will cause the appropriate MALFUNCTION or ERROR.  */
59d25dac7peter
60d25dac7peter/* Return the integer value of the given token WORD, as found in MAP. If the
61d25dac7peter   string is not recognized, then a MALFUNCTION will occur.
62d25dac7peter
63d25dac7peter   Note: this function is for persisted string values. Because this function
64d25dac7peter   will throw a MALFUNCTION, it should not be used for network input or
65d25dac7peter   user input.  */
66d25dac7peterint
67d25dac7petersvn_token__from_word_strict(const svn_token_map_t *map,
68d25dac7peter                            const char *word);
69d25dac7peter
70d25dac7peter
71d25dac7peter/* Store the integer value of WORD into *VALUE. If the string is not
72d25dac7peter   recognized, then SVN_ERR_BAD_TOKEN is returned.  */
73d25dac7petersvn_error_t *
74d25dac7petersvn_token__from_word_err(int *value,
75d25dac7peter                         const svn_token_map_t *map,
76d25dac7peter                         const char *word);
77d25dac7peter
78d25dac7peter
79d25dac7peter/* Return the integer value of the given token WORD as found in MAP. If the
80d25dac7peter   string is not recognized, then SVN_TOKEN_UNKNOWN will be returned.  */
81d25dac7peterint
82d25dac7petersvn_token__from_word(const svn_token_map_t *map,
83d25dac7peter                     const char *word);
84d25dac7peter
85d25dac7peter
86d25dac7peter/* Return the integer value of the given token WORD/LEN as found in MAP. If
87d25dac7peter   the string is not recognized, then SVN_TOKEN_UNKNOWN will be returned.  */
88d25dac7peterint
89d25dac7petersvn_token__from_mem(const svn_token_map_t *map,
90d25dac7peter                    const char *word,
91d25dac7peter                    apr_size_t len);
92d25dac7peter
93d25dac7peter
94d25dac7peter#ifdef __cplusplus
95d25dac7peter}
96d25dac7peter#endif /* __cplusplus */
97d25dac7peter
98d25dac7peter#endif /* SVN_TOKEN_H */
99