String stuff that should be in stdlib but isn't.
Dependents: X10Svr SSDP_Server
SW_String.h@0:6d899ce93ea0, 2016-04-11 (annotated)
- Committer:
- WiredHome
- Date:
- Mon Apr 11 02:25:34 2016 +0000
- Revision:
- 0:6d899ce93ea0
- Child:
- 1:65bc379d8cd0
Creation of some private string functions that were not part of the compiler library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WiredHome | 0:6d899ce93ea0 | 1 | /// @file SW_String.h This is a small collection of string utilities that |
WiredHome | 0:6d899ce93ea0 | 2 | /// are not consistent across compilers. |
WiredHome | 0:6d899ce93ea0 | 3 | /// |
WiredHome | 0:6d899ce93ea0 | 4 | /// @note Copyright © 2016 by Smartware Computing, all rights reserved. |
WiredHome | 0:6d899ce93ea0 | 5 | /// This software may be used to derive new software, as long as |
WiredHome | 0:6d899ce93ea0 | 6 | /// this copyright statement remains in the source file. |
WiredHome | 0:6d899ce93ea0 | 7 | /// @author David Smart |
WiredHome | 0:6d899ce93ea0 | 8 | /// |
WiredHome | 0:6d899ce93ea0 | 9 | #include "string.h" |
WiredHome | 0:6d899ce93ea0 | 10 | |
WiredHome | 0:6d899ce93ea0 | 11 | /// sw_tolower exists because not all compiler libraries have this function |
WiredHome | 0:6d899ce93ea0 | 12 | /// |
WiredHome | 0:6d899ce93ea0 | 13 | /// This takes a character and if it is upper-case, it converts it to |
WiredHome | 0:6d899ce93ea0 | 14 | /// lower-case and returns it. |
WiredHome | 0:6d899ce93ea0 | 15 | /// |
WiredHome | 0:6d899ce93ea0 | 16 | /// @note an alternate means would be a 256-entry lookup table. Very fast... |
WiredHome | 0:6d899ce93ea0 | 17 | /// |
WiredHome | 0:6d899ce93ea0 | 18 | /// @param a is the character to convert |
WiredHome | 0:6d899ce93ea0 | 19 | /// @returns the lower case equivalent to a |
WiredHome | 0:6d899ce93ea0 | 20 | /// |
WiredHome | 0:6d899ce93ea0 | 21 | char sw_tolower(char a); |
WiredHome | 0:6d899ce93ea0 | 22 | |
WiredHome | 0:6d899ce93ea0 | 23 | /// sw_strnicmp exists because not all compiler libraries have this function. |
WiredHome | 0:6d899ce93ea0 | 24 | /// |
WiredHome | 0:6d899ce93ea0 | 25 | /// In a case-insensitive compare, evaluate 'n' characters of the left and |
WiredHome | 0:6d899ce93ea0 | 26 | /// right referenced strings. |
WiredHome | 0:6d899ce93ea0 | 27 | /// |
WiredHome | 0:6d899ce93ea0 | 28 | /// @note Some compilers have strnicmp, others _strnicmp, and others have C++ |
WiredHome | 0:6d899ce93ea0 | 29 | /// methods, which is outside the scope of this C-portable set of functions. |
WiredHome | 0:6d899ce93ea0 | 30 | /// |
WiredHome | 0:6d899ce93ea0 | 31 | /// @param l is a pointer to the string on the left |
WiredHome | 0:6d899ce93ea0 | 32 | /// @param r is a pointer to the string on the right |
WiredHome | 0:6d899ce93ea0 | 33 | /// @param n is the number of characters to compare |
WiredHome | 0:6d899ce93ea0 | 34 | /// @returns -1 if l < r |
WiredHome | 0:6d899ce93ea0 | 35 | /// @returns 0 if l == r |
WiredHome | 0:6d899ce93ea0 | 36 | /// @returns +1 if l > r |
WiredHome | 0:6d899ce93ea0 | 37 | /// |
WiredHome | 0:6d899ce93ea0 | 38 | int sw_strnicmp(const char *l, const char *r, size_t n); |
WiredHome | 0:6d899ce93ea0 | 39 | |
WiredHome | 0:6d899ce93ea0 | 40 | /// sw_stristr exists because not all compiler libraries have this function. |
WiredHome | 0:6d899ce93ea0 | 41 | /// |
WiredHome | 0:6d899ce93ea0 | 42 | /// In a case-insenstive search, try to find the needle in the haystack. |
WiredHome | 0:6d899ce93ea0 | 43 | /// |
WiredHome | 0:6d899ce93ea0 | 44 | /// @param haystack is a pointer to string being searched |
WiredHome | 0:6d899ce93ea0 | 45 | /// @param needle is a pointer to a string to find |
WiredHome | 0:6d899ce93ea0 | 46 | /// @returns a pointer to the found needle in the haystack, or NULL |
WiredHome | 0:6d899ce93ea0 | 47 | /// |
WiredHome | 0:6d899ce93ea0 | 48 | const char * sw_stristr(const char * haystack, const char * needle); |
WiredHome | 0:6d899ce93ea0 | 49 | |
WiredHome | 0:6d899ce93ea0 | 50 | |
WiredHome | 0:6d899ce93ea0 | 51 | /// sw_stristr exists because not all compiler libraries have this function. |
WiredHome | 0:6d899ce93ea0 | 52 | /// |
WiredHome | 0:6d899ce93ea0 | 53 | /// In a case-insenstive search, try to find the needle in the haystack. |
WiredHome | 0:6d899ce93ea0 | 54 | /// |
WiredHome | 0:6d899ce93ea0 | 55 | /// @param haystack is a pointer to string being searched |
WiredHome | 0:6d899ce93ea0 | 56 | /// @param needle is a pointer to a string to find |
WiredHome | 0:6d899ce93ea0 | 57 | /// @returns a pointer to the found needle in the haystack, or NULL |
WiredHome | 0:6d899ce93ea0 | 58 | /// |
WiredHome | 0:6d899ce93ea0 | 59 | char * sw_stristr(char * haystack, const char * needle); |