ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

util.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #define FORBIDDEN_SYMBOL_EXCEPTION_isalnum
00024 #define FORBIDDEN_SYMBOL_EXCEPTION_isalpha
00025 #define FORBIDDEN_SYMBOL_EXCEPTION_isdigit
00026 #define FORBIDDEN_SYMBOL_EXCEPTION_isnumber
00027 #define FORBIDDEN_SYMBOL_EXCEPTION_islower
00028 #define FORBIDDEN_SYMBOL_EXCEPTION_isspace
00029 #define FORBIDDEN_SYMBOL_EXCEPTION_isupper
00030 #define FORBIDDEN_SYMBOL_EXCEPTION_isprint
00031 #define FORBIDDEN_SYMBOL_EXCEPTION_ispunct
00032 
00033 
00034 #include "common/util.h"
00035 #include "common/debug.h"
00036 
00037 namespace Common {
00038 
00039 //
00040 // Print hexdump of the data passed in
00041 //
00042 void hexdump(const byte *data, int len, int bytesPerLine, int startOffset) {
00043     assert(1 <= bytesPerLine && bytesPerLine <= 32);
00044     int i;
00045     byte c;
00046     int offset = startOffset;
00047     while (len >= bytesPerLine) {
00048         debugN("%06x: ", offset);
00049         for (i = 0; i < bytesPerLine; i++) {
00050             debugN("%02x ", data[i]);
00051             if (i % 4 == 3)
00052                 debugN(" ");
00053         }
00054         debugN(" |");
00055         for (i = 0; i < bytesPerLine; i++) {
00056             c = data[i];
00057             if (c < 32 || c >= 127)
00058                 c = '.';
00059             debugN("%c", c);
00060         }
00061         debugN("|\n");
00062         data += bytesPerLine;
00063         len -= bytesPerLine;
00064         offset += bytesPerLine;
00065     }
00066 
00067     if (len <= 0)
00068         return;
00069 
00070     debugN("%06x: ", offset);
00071     for (i = 0; i < bytesPerLine; i++) {
00072         if (i < len)
00073             debugN("%02x ", data[i]);
00074         else
00075             debugN("   ");
00076         if (i % 4 == 3)
00077             debugN(" ");
00078     }
00079     debugN(" |");
00080     for (i = 0; i < len; i++) {
00081         c = data[i];
00082         if (c < 32 || c >= 127)
00083             c = '.';
00084         debugN("%c", c);
00085     }
00086     for (; i < bytesPerLine; i++)
00087         debugN(" ");
00088     debugN("|\n");
00089 }
00090 
00091 
00092 #pragma mark -
00093 
00094 
00095 bool parseBool(const String &val, bool &valAsBool) {
00096     if (val.equalsIgnoreCase("true") ||
00097         val.equalsIgnoreCase("yes") ||
00098         val.equals("1")) {
00099         valAsBool = true;
00100         return true;
00101     }
00102     if (val.equalsIgnoreCase("false") ||
00103         val.equalsIgnoreCase("no") ||
00104         val.equals("0")) {
00105         valAsBool = false;
00106         return true;
00107     }
00108 
00109     return false;
00110 }
00111 
00112 
00113 #pragma mark -
00114 
00115 
00116 #define ENSURE_ASCII_CHAR(c) \
00117         if (c < 0 || c > 127) \
00118             return false
00119 
00120 bool isAlnum(int c) {
00121     ENSURE_ASCII_CHAR(c);
00122     return isalnum((byte)c);
00123 }
00124 
00125 bool isAlpha(int c) {
00126     ENSURE_ASCII_CHAR(c);
00127     return isalpha((byte)c);
00128 }
00129 
00130 bool isDigit(int c) {
00131     ENSURE_ASCII_CHAR(c);
00132     return isdigit((byte)c);
00133 }
00134 
00135 bool isLower(int c) {
00136     ENSURE_ASCII_CHAR(c);
00137     return islower((byte)c);
00138 }
00139 
00140 bool isSpace(int c) {
00141     ENSURE_ASCII_CHAR(c);
00142     return isspace((byte)c);
00143 }
00144 
00145 bool isUpper(int c) {
00146     ENSURE_ASCII_CHAR(c);
00147     return isupper((byte)c);
00148 }
00149 
00150 bool isPrint(int c) {
00151     ENSURE_ASCII_CHAR(c);
00152     return isprint((byte)c);
00153 }
00154 
00155 bool isPunct(int c) {
00156     ENSURE_ASCII_CHAR(c);
00157     return ispunct((byte)c);
00158 }
00159 
00160 } // End of namespace Common


Generated on Sat Mar 23 2019 05:02:20 for ResidualVM by doxygen 1.7.1
curved edge   curved edge