PageRenderTime 123ms CodeModel.GetById 61ms app.highlight 6ms RepoModel.GetById 54ms app.codeStats 0ms

/gecko_api/include/nsCRTGlue.h

http://firefox-mac-pdf.googlecode.com/
C++ Header | 136 lines | 40 code | 16 blank | 80 comment | 0 complexity | f82430300a341483735d7965dd2bd848 MD5 | raw file
  1/* ***** BEGIN LICENSE BLOCK *****
  2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3 *
  4 * The contents of this file are subject to the Mozilla Public License Version
  5 * 1.1 (the "License"); you may not use this file except in compliance with
  6 * the License. You may obtain a copy of the License at
  7 * http://www.mozilla.org/MPL/
  8 *
  9 * Software distributed under the License is distributed on an "AS IS" basis,
 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 11 * for the specific language governing rights and limitations under the
 12 * License.
 13 *
 14 * The Original Code is Mozilla XPCOM Glue.
 15 *
 16 * The Initial Developer of the Original Code is
 17 * the Mozilla Foundation <http://www.mozilla.org/>.
 18 *
 19 * Portions created by the Initial Developer are Copyright (C) 2005
 20 * the Initial Developer. All Rights Reserved.
 21 *
 22 * Contributor(s):
 23 *   Benjamin Smedberg <benjamin@smedbergs.us>
 24 *
 25 * Alternatively, the contents of this file may be used under the terms of
 26 * either the GNU General Public License Version 2 or later (the "GPL"), or
 27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 28 * in which case the provisions of the GPL or the LGPL are applicable instead
 29 * of those above. If you wish to allow use of your version of this file only
 30 * under the terms of either the GPL or the LGPL, and not to allow others to
 31 * use your version of this file under the terms of the MPL, indicate your
 32 * decision by deleting the provisions above and replace them with the notice
 33 * and other provisions required by the GPL or the LGPL. If you do not delete
 34 * the provisions above, a recipient may use your version of this file under
 35 * the terms of any one of the MPL, the GPL or the LGPL.
 36 *
 37 * ***** END LICENSE BLOCK ***** */
 38
 39#ifndef nsCRTGlue_h__
 40#define nsCRTGlue_h__
 41
 42#include "nscore.h"
 43
 44/**
 45 * Scan a string for the first character that is *not* in a set of
 46 * delimiters.  If the string is only delimiter characters, the end of the
 47 * string is returned.
 48 *
 49 * @param delims The set of delimiters (null-terminated)
 50 * @param str    The string to search (null-terminated)
 51 */
 52NS_COM_GLUE const char*
 53NS_strspnp(const char *delims, const char *str);
 54
 55/**
 56 * Tokenize a string. This function is similar to the strtok function in the
 57 * C standard library, but it does not use static variables to maintain state
 58 * and is therefore thread and reentrancy-safe.
 59 *
 60 * Any leading delimiters in str are skipped. Then the string is scanned
 61 * until an additional delimiter or end-of-string is found. The final
 62 * delimiter is set to '\0'.
 63 *
 64 * @param delims The set of delimiters.
 65 * @param str    The string to search. This is an in-out parameter; it is
 66 *               reset to the end of the found token + 1, or to the
 67 *               end-of-string if there are no more tokens.
 68 * @return       The token. If no token is found (the string is only
 69 *               delimiter characters), NULL is returned.
 70 */
 71NS_COM_GLUE char*
 72NS_strtok(const char *delims, char **str);
 73
 74/**
 75 * "strlen" for PRUnichar strings
 76 */
 77NS_COM_GLUE PRUint32
 78NS_strlen(const PRUnichar *aString);
 79
 80/**
 81 * "strcmp" for PRUnichar strings
 82 */
 83NS_COM_GLUE int
 84NS_strcmp(const PRUnichar *a, const PRUnichar *b);
 85
 86/**
 87 * "strdup" for PRUnichar strings, uses the NS_Alloc allocator.
 88 */
 89NS_COM_GLUE PRUnichar*
 90NS_strdup(const PRUnichar *aString);
 91
 92/**
 93 * "strdup", but using the NS_Alloc allocator.
 94 */
 95NS_COM_GLUE char*
 96NS_strdup(const char *aString);
 97
 98/**
 99 * strndup for PRUnichar strings... this function will ensure that the
100 * new string is null-terminated. Uses the NS_Alloc allocator.
101 */
102NS_COM_GLUE PRUnichar*
103NS_strndup(const PRUnichar *aString, PRUint32 aLen);
104
105// The following case-conversion methods only deal in the ascii repertoire
106// A-Z and a-z
107
108// semi-private data declarations... don't use these directly.
109class NS_COM_GLUE nsLowerUpperUtils {
110public:
111  static const unsigned char kLower2Upper[256];
112  static const unsigned char kUpper2Lower[256];
113};
114
115inline char NS_ToUpper(char aChar)
116{
117  return (char)nsLowerUpperUtils::kLower2Upper[(unsigned char)aChar];
118}
119
120inline char NS_ToLower(char aChar)
121{
122  return (char)nsLowerUpperUtils::kUpper2Lower[(unsigned char)aChar];
123}
124  
125NS_COM_GLUE PRBool NS_IsUpper(char aChar);
126NS_COM_GLUE PRBool NS_IsLower(char aChar);
127
128NS_COM_GLUE PRBool NS_IsAscii(PRUnichar aChar);
129NS_COM_GLUE PRBool NS_IsAscii(const PRUnichar* aString);
130NS_COM_GLUE PRBool NS_IsAsciiAlpha(PRUnichar aChar);
131NS_COM_GLUE PRBool NS_IsAsciiDigit(PRUnichar aChar);
132NS_COM_GLUE PRBool NS_IsAsciiWhitespace(PRUnichar aChar);
133NS_COM_GLUE PRBool NS_IsAscii(const char* aString);
134NS_COM_GLUE PRBool NS_IsAscii(const char* aString, PRUint32 aLength);
135
136#endif // nsCRTGlue_h__