juce_CharacterFunctions.h

Go to the documentation of this file.
00001 /*
00002   ==============================================================================
00003 
00004    This file is part of the JUCE library - "Jules' Utility Class Extensions"
00005    Copyright 2004-7 by Raw Material Software ltd.
00006 
00007   ------------------------------------------------------------------------------
00008 
00009    JUCE can be redistributed and/or modified under the terms of the
00010    GNU General Public License, as published by the Free Software Foundation;
00011    either version 2 of the License, or (at your option) any later version.
00012 
00013    JUCE is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with JUCE; if not, visit www.gnu.org/licenses or write to the
00020    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00021    Boston, MA 02111-1307 USA
00022 
00023   ------------------------------------------------------------------------------
00024 
00025    If you'd like to release a closed-source product which uses JUCE, commercial
00026    licenses are also available: visit www.rawmaterialsoftware.com/juce for
00027    more information.
00028 
00029   ==============================================================================
00030 */
00031 
00032 #ifndef __JUCE_CHARACTERFUNCTIONS_JUCEHEADER__
00033 #define __JUCE_CHARACTERFUNCTIONS_JUCEHEADER__
00034 
00035 
00036 //==============================================================================
00037 /* The String class can either use wchar_t unicode characters, or 8-bit characters
00038    (in the default system encoding) as its internal representation.
00039 
00040    To use unicode, define the JUCE_STRINGS_ARE_UNICODE macro in juce_Config.h
00041 
00042    Be sure to use "tchar" for characters rather than "char", and always wrap string
00043    literals in the T("abcd") macro, so that it all works nicely either way round.
00044 */
00045 #if JUCE_STRINGS_ARE_UNICODE
00046 
00047   #define JUCE_T(stringLiteral)     (L##stringLiteral)
00048   typedef juce_wchar                tchar;
00049   #define juce_tcharToWideChar(c)   (c)
00050 
00051 #else
00052 
00053   #define JUCE_T(stringLiteral)     (stringLiteral)
00054   typedef char                      tchar;
00055   #define juce_tcharToWideChar(c)   ((juce_wchar) (unsigned char) (c))
00056 
00057 #endif
00058 
00059 #if ! JUCE_DONT_DEFINE_MACROS
00060 
00073 #define T(stringLiteral)            JUCE_T(stringLiteral)
00074 
00075 #endif
00076 
00077 //==============================================================================
00088 class JUCE_API  CharacterFunctions
00089 {
00090 public:
00091     static int length (const char* const s) throw();
00092     static int length (const juce_wchar* const s) throw();
00093 
00094     static void copy (char* dest, const char* src, const int maxBytes) throw();
00095     static void copy (juce_wchar* dest, const juce_wchar* src, const int maxChars) throw();
00096 
00097     static void copy (juce_wchar* dest, const char* src, const int maxChars) throw();
00098     static void copy (char* dest, const juce_wchar* src, const int maxBytes) throw();
00099     static int bytesRequiredForCopy (const juce_wchar* src) throw();
00100 
00101     static void append (char* dest, const char* src) throw();
00102     static void append (juce_wchar* dest, const juce_wchar* src) throw();
00103 
00104     static int compare (const char* const s1, const char* const s2) throw();
00105     static int compare (const juce_wchar* s1, const juce_wchar* s2) throw();
00106 
00107     static int compare (const char* const s1, const char* const s2, const int maxChars) throw();
00108     static int compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw();
00109 
00110     static int compareIgnoreCase (const char* const s1, const char* const s2) throw();
00111     static int compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw();
00112 
00113     static int compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw();
00114     static int compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw();
00115 
00116     static const char* find (const char* const haystack, const char* const needle) throw();
00117     static const juce_wchar* find (const juce_wchar* haystack, const juce_wchar* const needle) throw();
00118 
00119     static int indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw();
00120     static int indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw();
00121 
00122     static int indexOfCharFast (const char* const haystack, const char needle) throw();
00123     static int indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw();
00124 
00125     static int getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw();
00126     static int getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw();
00127 
00128     static int ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw();
00129     static int ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw();
00130 
00131     static int getIntValue (const char* const s) throw();
00132     static int getIntValue (const juce_wchar* s) throw();
00133 
00134     static int64 getInt64Value (const char* s) throw();
00135     static int64 getInt64Value (const juce_wchar* s) throw();
00136 
00137     static double getDoubleValue (const char* const s) throw();
00138     static double getDoubleValue (const juce_wchar* const s) throw();
00139 
00140     //==============================================================================
00141     static char toUpperCase (const char character) throw();
00142     static juce_wchar toUpperCase (const juce_wchar character) throw();
00143     static void toUpperCase (char* s) throw();
00144 
00145     static void toUpperCase (juce_wchar* s) throw();
00146     static bool isUpperCase (const char character) throw();
00147     static bool isUpperCase (const juce_wchar character) throw();
00148 
00149     static char toLowerCase (const char character) throw();
00150     static juce_wchar toLowerCase (const juce_wchar character) throw();
00151     static void toLowerCase (char* s) throw();
00152     static void toLowerCase (juce_wchar* s) throw();
00153     static bool isLowerCase (const char character) throw();
00154     static bool isLowerCase (const juce_wchar character) throw();
00155 
00156     //==============================================================================
00157     static bool isWhitespace (const char character) throw();
00158     static bool isWhitespace (const juce_wchar character) throw();
00159 
00160     static bool isDigit (const char character) throw();
00161     static bool isDigit (const juce_wchar character) throw();
00162 
00163     static bool isLetter (const char character) throw();
00164     static bool isLetter (const juce_wchar character) throw();
00165 
00166     static bool isLetterOrDigit (const char character) throw();
00167     static bool isLetterOrDigit (const juce_wchar character) throw();
00168 
00172     static int getHexDigitValue (const tchar digit) throw();
00173 
00174     //==============================================================================
00175     static int printf (char* const dest, const int maxLength, const char* const format, ...) throw();
00176     static int printf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, ...) throw();
00177 
00178     static int vprintf (char* const dest, const int maxLength, const char* const format, va_list& args) throw();
00179     static int vprintf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, va_list& args) throw();
00180 };
00181 
00182 #endif   // __JUCE_CHARACTERFUNCTIONS_JUCEHEADER__