/* Copyright (c) 2004 Joseph Gleason Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Current versions of this and other code can be downloaded at: http://gleason.cc/ */ #ifndef STR2TOK_H #define STR2TOK_H /* * Separates S into N strings delimited by any characters * in Delims. * A group of delimiters togather are treated as a single delimiter. * ex: str2tok("cat dog"," ",...) yeilds "cat" and "dog" just like * str2tok("cat dog"," ",...) * If any of the output strings are longer than MaxLength, * they are truncated and null terminated. * If there are more string in s than MaxStrings, str2tok only returns * the first MaxStrings of them. * * * Returns: returns a 2d array of output strings. NOTE: * THIS 2D ARRAY IS MALLOCED WITHIN STR2TOK. THE USER IS HOWEVER * RESPONCIBLE FOR FREE()ing IT MANUALLY OR USING * STR2TOK_CLEANUP. free(StringArray) is not sufficent * as each entry must be individually freed (as _cleanup does) * * StringCount is set to the number of strings found * or MaxStrings if there are MaxStrings or more * * MaxStrings and MaxLength must both be positive * s and Delims must point to null terminated strings * (which may be of zero length) */ #include char** str2tok(char* s, char* Delims, int *StringCount, int MaxStrings, size_t MaxLength); void str2tok_cleanup(char** StringArray, int StringCount); /* strtrimws trim whitespace at the begining or end of s Modifies s whitespace is defined by isspace() */ void strtrimws(char* s); #endif