1251881Speter/* svn_token.h : value/string-token functions 2251881Speter * 3251881Speter * ==================================================================== 4251881Speter * Licensed to the Apache Software Foundation (ASF) under one 5251881Speter * or more contributor license agreements. See the NOTICE file 6251881Speter * distributed with this work for additional information 7251881Speter * regarding copyright ownership. The ASF licenses this file 8251881Speter * to you under the Apache License, Version 2.0 (the 9251881Speter * "License"); you may not use this file except in compliance 10251881Speter * with the License. You may obtain a copy of the License at 11251881Speter * 12251881Speter * http://www.apache.org/licenses/LICENSE-2.0 13251881Speter * 14251881Speter * Unless required by applicable law or agreed to in writing, 15251881Speter * software distributed under the License is distributed on an 16251881Speter * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17251881Speter * KIND, either express or implied. See the License for the 18251881Speter * specific language governing permissions and limitations 19251881Speter * under the License. 20251881Speter * ==================================================================== 21251881Speter */ 22251881Speter 23251881Speter#ifndef SVN_TOKEN_H 24251881Speter#define SVN_TOKEN_H 25251881Speter 26251881Speter 27251881Speter#include "svn_error.h" 28251881Speter 29251881Speter 30251881Speter#ifdef __cplusplus 31251881Speterextern "C" { 32251881Speter#endif /* __cplusplus */ 33251881Speter 34251881Speter 35251881Speter/** A mapping between a string STR and an enumeration value VAL. 36251881Speter * 37251881Speter * Maps are an array of these, terminated with a struct where STR == NULL. 38251881Speter */ 39251881Spetertypedef struct svn_token_map_t 40251881Speter{ 41251881Speter const char *str; 42251881Speter int val; 43251881Speter} svn_token_map_t; 44251881Speter 45251881Speter 46251881Speter/* A value used by some token functions to indicate an unrecognized token. */ 47251881Speter#define SVN_TOKEN_UNKNOWN (-9999) 48251881Speter 49251881Speter 50251881Speter/* Return the string form of the given VALUE as found in MAP. If the value 51251881Speter is not recognized, then a MALFUNCTION will occur. */ 52251881Speterconst char * 53251881Spetersvn_token__to_word(const svn_token_map_t *map, 54251881Speter int value); 55251881Speter 56251881Speter 57251881Speter/* NOTE: in the following functions, if WORD is NULL, then SVN_TOKEN_UNKNOWN 58251881Speter will be returned, or will cause the appropriate MALFUNCTION or ERROR. */ 59251881Speter 60251881Speter/* Return the integer value of the given token WORD, as found in MAP. If the 61251881Speter string is not recognized, then a MALFUNCTION will occur. 62251881Speter 63251881Speter Note: this function is for persisted string values. Because this function 64251881Speter will throw a MALFUNCTION, it should not be used for network input or 65251881Speter user input. */ 66251881Speterint 67251881Spetersvn_token__from_word_strict(const svn_token_map_t *map, 68251881Speter const char *word); 69251881Speter 70251881Speter 71251881Speter/* Store the integer value of WORD into *VALUE. If the string is not 72251881Speter recognized, then SVN_ERR_BAD_TOKEN is returned. */ 73251881Spetersvn_error_t * 74251881Spetersvn_token__from_word_err(int *value, 75251881Speter const svn_token_map_t *map, 76251881Speter const char *word); 77251881Speter 78251881Speter 79251881Speter/* Return the integer value of the given token WORD as found in MAP. If the 80251881Speter string is not recognized, then SVN_TOKEN_UNKNOWN will be returned. */ 81251881Speterint 82251881Spetersvn_token__from_word(const svn_token_map_t *map, 83251881Speter const char *word); 84251881Speter 85251881Speter 86251881Speter/* Return the integer value of the given token WORD/LEN as found in MAP. If 87251881Speter the string is not recognized, then SVN_TOKEN_UNKNOWN will be returned. */ 88251881Speterint 89251881Spetersvn_token__from_mem(const svn_token_map_t *map, 90251881Speter const char *word, 91251881Speter apr_size_t len); 92251881Speter 93251881Speter 94251881Speter#ifdef __cplusplus 95251881Speter} 96251881Speter#endif /* __cplusplus */ 97251881Speter 98251881Speter#endif /* SVN_TOKEN_H */ 99