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