2 * token.c : value/string-token functions
4 * ====================================================================
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
21 * ====================================================================
24 #include "svn_types.h"
25 #include "svn_error.h"
27 #include "private/svn_token.h"
28 #include "svn_private_config.h"
32 svn_token__to_word(const svn_token_map_t *map,
35 for (; map->str != NULL; ++map)
36 if (map->val == value)
39 /* Internal, numeric values should always be found. */
40 SVN_ERR_MALFUNCTION_NO_RETURN();
45 svn_token__from_word_strict(const svn_token_map_t *map,
48 int value = svn_token__from_word(map, word);
50 if (value == SVN_TOKEN_UNKNOWN)
51 SVN_ERR_MALFUNCTION_NO_RETURN();
58 svn_token__from_word_err(int *value,
59 const svn_token_map_t *map,
62 *value = svn_token__from_word(map, word);
64 if (*value == SVN_TOKEN_UNKNOWN)
65 return svn_error_createf(SVN_ERR_BAD_TOKEN, NULL,
66 _("Token '%s' is unrecognized"),
74 svn_token__from_word(const svn_token_map_t *map,
78 return SVN_TOKEN_UNKNOWN;
80 for (; map->str != NULL; ++map)
81 if (strcmp(map->str, word) == 0)
84 return SVN_TOKEN_UNKNOWN;
89 svn_token__from_mem(const svn_token_map_t *map,
93 for (; map->str != NULL; ++map)
94 if (strncmp(map->str, word, len) == 0 && map->str[len] == '\0')
97 return SVN_TOKEN_UNKNOWN;