| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../include/fxcrt/fx_basic.h" | 7 #include "../../include/fxcrt/fx_basic.h" |
| 8 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | 8 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <dirent.h> | 10 #include <dirent.h> |
| 11 #else | 11 #else |
| 12 #include <direct.h> | 12 #include <direct.h> |
| 13 #endif | 13 #endif |
| 14 CFX_PrivateData::~CFX_PrivateData() | 14 CFX_PrivateData::~CFX_PrivateData() { |
| 15 { | 15 ClearAll(); |
| 16 ClearAll(); | 16 } |
| 17 } | 17 void FX_PRIVATEDATA::FreeData() { |
| 18 void FX_PRIVATEDATA::FreeData() | 18 if (m_pData == NULL) { |
| 19 { | 19 return; |
| 20 if (m_pData == NULL) { | 20 } |
| 21 return; | 21 if (m_bSelfDestruct) { |
| 22 } | 22 delete (CFX_DestructObject*)m_pData; |
| 23 if (m_bSelfDestruct) { | 23 } else if (m_pCallback) { |
| 24 delete (CFX_DestructObject*)m_pData; | 24 m_pCallback(m_pData); |
| 25 } else if (m_pCallback) { | 25 } |
| 26 m_pCallback(m_pData); | 26 } |
| 27 } | 27 void CFX_PrivateData::AddData(void* pModuleId, |
| 28 } | 28 void* pData, |
| 29 void CFX_PrivateData::AddData(void* pModuleId, void* pData, PD_CALLBACK_FREEDATA
callback, FX_BOOL bSelfDestruct) | 29 PD_CALLBACK_FREEDATA callback, |
| 30 { | 30 FX_BOOL bSelfDestruct) { |
| 31 if (pModuleId == NULL) { | 31 if (pModuleId == NULL) { |
| 32 return; | 32 return; |
| 33 } | 33 } |
| 34 FX_PRIVATEDATA* pList = m_DataList.GetData(); | 34 FX_PRIVATEDATA* pList = m_DataList.GetData(); |
| 35 int count = m_DataList.GetSize(); | 35 int count = m_DataList.GetSize(); |
| 36 for (int i = 0; i < count; i ++) { | 36 for (int i = 0; i < count; i++) { |
| 37 if (pList[i].m_pModuleId == pModuleId) { | 37 if (pList[i].m_pModuleId == pModuleId) { |
| 38 pList[i].FreeData(); | 38 pList[i].FreeData(); |
| 39 pList[i].m_pData = pData; | 39 pList[i].m_pData = pData; |
| 40 pList[i].m_pCallback = callback; | 40 pList[i].m_pCallback = callback; |
| 41 return; | 41 return; |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 FX_PRIVATEDATA data = {pModuleId, pData, callback, bSelfDestruct}; | 44 FX_PRIVATEDATA data = {pModuleId, pData, callback, bSelfDestruct}; |
| 45 m_DataList.Add(data); | 45 m_DataList.Add(data); |
| 46 } | 46 } |
| 47 void CFX_PrivateData::SetPrivateData(void* pModuleId, void* pData, PD_CALLBACK_F
REEDATA callback) | 47 void CFX_PrivateData::SetPrivateData(void* pModuleId, |
| 48 { | 48 void* pData, |
| 49 AddData(pModuleId, pData, callback, FALSE); | 49 PD_CALLBACK_FREEDATA callback) { |
| 50 } | 50 AddData(pModuleId, pData, callback, FALSE); |
| 51 void CFX_PrivateData::SetPrivateObj(void* pModuleId, CFX_DestructObject* pObj) | 51 } |
| 52 { | 52 void CFX_PrivateData::SetPrivateObj(void* pModuleId, CFX_DestructObject* pObj) { |
| 53 AddData(pModuleId, pObj, NULL, TRUE); | 53 AddData(pModuleId, pObj, NULL, TRUE); |
| 54 } | 54 } |
| 55 FX_BOOL CFX_PrivateData::RemovePrivateData(void* pModuleId) | 55 FX_BOOL CFX_PrivateData::RemovePrivateData(void* pModuleId) { |
| 56 { | 56 if (pModuleId == NULL) { |
| 57 if (pModuleId == NULL) { | 57 return FALSE; |
| 58 return FALSE; | 58 } |
| 59 } | 59 FX_PRIVATEDATA* pList = m_DataList.GetData(); |
| 60 FX_PRIVATEDATA* pList = m_DataList.GetData(); | 60 int count = m_DataList.GetSize(); |
| 61 int count = m_DataList.GetSize(); | 61 for (int i = 0; i < count; i++) { |
| 62 for (int i = 0; i < count; i ++) { | 62 if (pList[i].m_pModuleId == pModuleId) { |
| 63 if (pList[i].m_pModuleId == pModuleId) { | 63 m_DataList.RemoveAt(i); |
| 64 m_DataList.RemoveAt(i); | 64 return TRUE; |
| 65 return TRUE; | 65 } |
| 66 } | 66 } |
| 67 } | 67 return FALSE; |
| 68 return FALSE; | 68 } |
| 69 } | 69 void* CFX_PrivateData::GetPrivateData(void* pModuleId) { |
| 70 void* CFX_PrivateData::GetPrivateData(void* pModuleId) | 70 if (pModuleId == NULL) { |
| 71 { | |
| 72 if (pModuleId == NULL) { | |
| 73 return NULL; | |
| 74 } | |
| 75 FX_PRIVATEDATA* pList = m_DataList.GetData(); | |
| 76 int count = m_DataList.GetSize(); | |
| 77 for (int i = 0; i < count; i ++) { | |
| 78 if (pList[i].m_pModuleId == pModuleId) { | |
| 79 return pList[i].m_pData; | |
| 80 } | |
| 81 } | |
| 82 return NULL; | 71 return NULL; |
| 83 } | 72 } |
| 84 void CFX_PrivateData::ClearAll() | 73 FX_PRIVATEDATA* pList = m_DataList.GetData(); |
| 85 { | 74 int count = m_DataList.GetSize(); |
| 86 FX_PRIVATEDATA* pList = m_DataList.GetData(); | 75 for (int i = 0; i < count; i++) { |
| 87 int count = m_DataList.GetSize(); | 76 if (pList[i].m_pModuleId == pModuleId) { |
| 88 for (int i = 0; i < count; i ++) { | 77 return pList[i].m_pData; |
| 89 pList[i].FreeData(); | 78 } |
| 90 } | 79 } |
| 91 m_DataList.RemoveAll(); | 80 return NULL; |
| 92 } | 81 } |
| 93 void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) | 82 void CFX_PrivateData::ClearAll() { |
| 94 { | 83 FX_PRIVATEDATA* pList = m_DataList.GetData(); |
| 95 if (FXSYS_memchr(strc.GetPtr(), '.', strc.GetLength()) == NULL) { | 84 int count = m_DataList.GetSize(); |
| 96 bInteger = TRUE; | 85 for (int i = 0; i < count; i++) { |
| 97 int cc = 0, integer = 0; | 86 pList[i].FreeData(); |
| 98 const FX_CHAR* str = strc.GetCStr(); | 87 } |
| 99 int len = strc.GetLength(); | 88 m_DataList.RemoveAll(); |
| 100 FX_BOOL bNegative = FALSE; | 89 } |
| 101 if (str[0] == '+') { | 90 void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) { |
| 102 cc++; | 91 if (FXSYS_memchr(strc.GetPtr(), '.', strc.GetLength()) == NULL) { |
| 103 } else if (str[0] == '-') { | 92 bInteger = TRUE; |
| 104 bNegative = TRUE; | 93 int cc = 0, integer = 0; |
| 105 cc++; | |
| 106 } | |
| 107 while (cc < len) { | |
| 108 if (str[cc] < '0' || str[cc] > '9') { | |
| 109 break; | |
| 110 } | |
| 111 integer = integer * 10 + str[cc] - '0'; | |
| 112 if (integer < 0) { | |
| 113 break; | |
| 114 } | |
| 115 cc ++; | |
| 116 } | |
| 117 if (bNegative) { | |
| 118 integer = -integer; | |
| 119 } | |
| 120 *(int*)pData = integer; | |
| 121 } else { | |
| 122 bInteger = FALSE; | |
| 123 *(FX_FLOAT*)pData = FX_atof(strc); | |
| 124 } | |
| 125 } | |
| 126 FX_FLOAT FX_atof(const CFX_ByteStringC& strc) | |
| 127 { | |
| 128 if (strc.GetLength() == 0) { | |
| 129 return 0.0; | |
| 130 } | |
| 131 int cc = 0; | |
| 132 FX_BOOL bNegative = FALSE; | |
| 133 const FX_CHAR* str = strc.GetCStr(); | 94 const FX_CHAR* str = strc.GetCStr(); |
| 134 int len = strc.GetLength(); | 95 int len = strc.GetLength(); |
| 96 FX_BOOL bNegative = FALSE; |
| 135 if (str[0] == '+') { | 97 if (str[0] == '+') { |
| 136 cc++; | 98 cc++; |
| 137 } else if (str[0] == '-') { | 99 } else if (str[0] == '-') { |
| 138 bNegative = TRUE; | 100 bNegative = TRUE; |
| 139 cc++; | 101 cc++; |
| 140 } | 102 } |
| 141 while (cc < len) { | 103 while (cc < len) { |
| 142 if (str[cc] != '+' && str[cc] != '-') { | 104 if (str[cc] < '0' || str[cc] > '9') { |
| 143 break; | 105 break; |
| 144 } | 106 } |
| 145 cc ++; | 107 integer = integer * 10 + str[cc] - '0'; |
| 146 } | 108 if (integer < 0) { |
| 147 FX_FLOAT value = 0; | 109 break; |
| 110 } |
| 111 cc++; |
| 112 } |
| 113 if (bNegative) { |
| 114 integer = -integer; |
| 115 } |
| 116 *(int*)pData = integer; |
| 117 } else { |
| 118 bInteger = FALSE; |
| 119 *(FX_FLOAT*)pData = FX_atof(strc); |
| 120 } |
| 121 } |
| 122 FX_FLOAT FX_atof(const CFX_ByteStringC& strc) { |
| 123 if (strc.GetLength() == 0) { |
| 124 return 0.0; |
| 125 } |
| 126 int cc = 0; |
| 127 FX_BOOL bNegative = FALSE; |
| 128 const FX_CHAR* str = strc.GetCStr(); |
| 129 int len = strc.GetLength(); |
| 130 if (str[0] == '+') { |
| 131 cc++; |
| 132 } else if (str[0] == '-') { |
| 133 bNegative = TRUE; |
| 134 cc++; |
| 135 } |
| 136 while (cc < len) { |
| 137 if (str[cc] != '+' && str[cc] != '-') { |
| 138 break; |
| 139 } |
| 140 cc++; |
| 141 } |
| 142 FX_FLOAT value = 0; |
| 143 while (cc < len) { |
| 144 if (str[cc] == '.') { |
| 145 break; |
| 146 } |
| 147 value = value * 10 + str[cc] - '0'; |
| 148 cc++; |
| 149 } |
| 150 static const FX_FLOAT fraction_scales[] = { |
| 151 0.1f, 0.01f, 0.001f, 0.0001f, |
| 152 0.00001f, 0.000001f, 0.0000001f, 0.00000001f, |
| 153 0.000000001f, 0.0000000001f, 0.00000000001f}; |
| 154 int scale = 0; |
| 155 if (cc < len && str[cc] == '.') { |
| 156 cc++; |
| 148 while (cc < len) { | 157 while (cc < len) { |
| 149 if (str[cc] == '.') { | 158 value += fraction_scales[scale] * (str[cc] - '0'); |
| 150 break; | 159 scale++; |
| 151 } | 160 if (scale == sizeof fraction_scales / sizeof(FX_FLOAT)) { |
| 152 value = value * 10 + str[cc] - '0'; | 161 break; |
| 153 cc ++; | 162 } |
| 154 } | 163 cc++; |
| 155 static const FX_FLOAT fraction_scales[] = {0.1f, 0.01f, 0.001f, 0.0001f, 0.0
0001f, 0.000001f, | 164 } |
| 156 0.0000001f, 0.00000001f, 0.000000
001f, 0.0000000001f, 0.00000000001f | 165 } |
| 157 }; | 166 return bNegative ? -value : value; |
| 158 int scale = 0; | |
| 159 if (cc < len && str[cc] == '.') { | |
| 160 cc ++; | |
| 161 while (cc < len) { | |
| 162 value += fraction_scales[scale] * (str[cc] - '0'); | |
| 163 scale ++; | |
| 164 if (scale == sizeof fraction_scales / sizeof(FX_FLOAT)) { | |
| 165 break; | |
| 166 } | |
| 167 cc ++; | |
| 168 } | |
| 169 } | |
| 170 return bNegative ? -value : value; | |
| 171 } | 167 } |
| 172 | 168 |
| 173 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 | 169 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 |
| 174 void FXSYS_snprintf(char *str, size_t size, _Printf_format_string_ const char* f
mt, ...) | 170 void FXSYS_snprintf(char* str, |
| 175 { | 171 size_t size, |
| 176 va_list ap; | 172 _Printf_format_string_ const char* fmt, |
| 177 va_start(ap, fmt); | 173 ...) { |
| 178 FXSYS_vsnprintf(str, size, fmt, ap); | 174 va_list ap; |
| 179 va_end(ap); | 175 va_start(ap, fmt); |
| 180 } | 176 FXSYS_vsnprintf(str, size, fmt, ap); |
| 181 void FXSYS_vsnprintf(char *str, size_t size, const char* fmt, va_list ap) | 177 va_end(ap); |
| 182 { | 178 } |
| 183 (void) _vsnprintf(str, size, fmt, ap); | 179 void FXSYS_vsnprintf(char* str, size_t size, const char* fmt, va_list ap) { |
| 184 if (size) { | 180 (void)_vsnprintf(str, size, fmt, ap); |
| 185 str[size - 1] = 0; | 181 if (size) { |
| 186 } | 182 str[size - 1] = 0; |
| 183 } |
| 187 } | 184 } |
| 188 #endif // _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 | 185 #endif // _FXM_PLATFORM_WINDOWS_ && _MSC_VER < 1900 |
| 189 | 186 |
| 190 static FX_BOOL FX_IsDigit(uint8_t ch) | 187 static FX_BOOL FX_IsDigit(uint8_t ch) { |
| 191 { | 188 return (ch >= '0' && ch <= '9') ? TRUE : FALSE; |
| 192 return (ch >= '0' && ch <= '9') ? TRUE : FALSE; | 189 } |
| 193 } | 190 static FX_BOOL FX_IsXDigit(uint8_t ch) { |
| 194 static FX_BOOL FX_IsXDigit(uint8_t ch) | 191 return (FX_IsDigit(ch) || (ch >= 'A' && ch <= 'F') || |
| 195 { | 192 (ch >= 'a' && ch <= 'f')) |
| 196 return (FX_IsDigit(ch) || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f
')) ? TRUE : FALSE; | 193 ? TRUE |
| 197 } | 194 : FALSE; |
| 198 static uint8_t FX_MakeUpper(uint8_t ch) | 195 } |
| 199 { | 196 static uint8_t FX_MakeUpper(uint8_t ch) { |
| 200 if (ch < 'a' || ch > 'z') { | 197 if (ch < 'a' || ch > 'z') { |
| 201 return ch; | 198 return ch; |
| 202 } | 199 } |
| 203 return ch - 32; | 200 return ch - 32; |
| 204 } | 201 } |
| 205 static int FX_HexToI(uint8_t ch) | 202 static int FX_HexToI(uint8_t ch) { |
| 206 { | 203 ch = FX_MakeUpper(ch); |
| 207 ch = FX_MakeUpper(ch); | 204 return FX_IsDigit(ch) ? (ch - '0') : (ch - 55); |
| 208 return FX_IsDigit(ch) ? (ch - '0') : (ch - 55); | |
| 209 } | 205 } |
| 210 static const unsigned char url_encodeTable[128] = { | 206 static const unsigned char url_encodeTable[128] = { |
| 211 1, 1, 1, 1,» » 1, 1, 1, 1, | 207 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 212 1, 1, 1, 1,» » 1, 1, 1, 1, | 208 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, |
| 213 1, 1, 1, 1,» » 1, 1, 1, 1, | 209 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, |
| 214 1, 1, 1, 1,» » 1, 1, 1, 1, | 210 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 215 1, 0, 1, 1,» » 0, 1, 0, 0, | 211 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 216 0, 0, 0, 0,» » 0, 0, 0, 0, | 212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, |
| 217 0, 0, 0, 0,» » 0, 0, 0, 0, | |
| 218 0, 0, 0, 0,» » 1, 0, 1, 0, | |
| 219 0, 0, 0, 0,» » 0, 0, 0, 0, | |
| 220 0, 0, 0, 0,» » 0, 0, 0, 0, | |
| 221 0, 0, 0, 0,» » 0, 0, 0, 0, | |
| 222 0, 0, 0, 1,» » 1, 1, 1, 0, | |
| 223 1, 0, 0, 0,» » 0, 0, 0, 0, | |
| 224 0, 0, 0, 0,» » 0, 0, 0, 0, | |
| 225 0, 0, 0, 0,» » 0, 0, 0, 0, | |
| 226 0, 0, 0, 1,» » 1, 1, 1, 1, | |
| 227 }; | 213 }; |
| 228 CFX_ByteString FX_UrlEncode(const CFX_WideString& wsUrl) | 214 CFX_ByteString FX_UrlEncode(const CFX_WideString& wsUrl) { |
| 229 { | 215 const char arDigits[] = "0123456789ABCDEF"; |
| 230 const char arDigits[] = "0123456789ABCDEF"; | 216 CFX_ByteString rUrl; |
| 231 CFX_ByteString rUrl; | 217 int nLength = wsUrl.GetLength(); |
| 232 int nLength = wsUrl.GetLength(); | 218 for (int i = 0; i < nLength; i++) { |
| 233 for (int i = 0; i < nLength; i++) { | 219 FX_DWORD word = wsUrl.GetAt(i); |
| 234 FX_DWORD word = wsUrl.GetAt(i); | 220 if (word > 0x7F || url_encodeTable[word] == 1) { |
| 235 if (word > 0x7F || url_encodeTable[word] == 1) { | 221 CFX_ByteString bsUri = CFX_ByteString::FromUnicode((FX_WORD)word); |
| 236 CFX_ByteString bsUri = CFX_ByteString::FromUnicode((FX_WORD)word); | 222 int nByte = bsUri.GetLength(); |
| 237 int nByte = bsUri.GetLength(); | 223 for (int j = 0; j < nByte; j++) { |
| 238 for (int j = 0; j < nByte; j++) { | 224 rUrl += '%'; |
| 239 rUrl += '%'; | 225 uint8_t code = bsUri.GetAt(j); |
| 240 uint8_t code = bsUri.GetAt(j); | 226 rUrl += arDigits[code >> 4]; |
| 241 rUrl += arDigits[code >> 4]; | 227 rUrl += arDigits[code & 0x0F]; |
| 242 rUrl += arDigits[code & 0x0F]; | 228 } |
| 243 } | 229 } else { |
| 244 } else { | 230 rUrl += CFX_ByteString::FromUnicode((FX_WORD)word); |
| 245 rUrl += CFX_ByteString::FromUnicode((FX_WORD)word); | 231 } |
| 246 } | 232 } |
| 247 } | 233 return rUrl; |
| 248 return rUrl; | 234 } |
| 249 } | 235 CFX_WideString FX_UrlDecode(const CFX_ByteString& bsUrl) { |
| 250 CFX_WideString FX_UrlDecode(const CFX_ByteString& bsUrl) | 236 CFX_ByteString rUrl; |
| 251 { | 237 int nLength = bsUrl.GetLength(); |
| 252 CFX_ByteString rUrl; | 238 for (int i = 0; i < nLength; i++) { |
| 253 int nLength = bsUrl.GetLength(); | 239 if (i < nLength - 2 && bsUrl[i] == '%' && FX_IsXDigit(bsUrl[i + 1]) && |
| 254 for (int i = 0; i < nLength; i++) { | 240 FX_IsXDigit(bsUrl[i + 2])) { |
| 255 if (i < nLength - 2 && bsUrl[i] == '%' && FX_IsXDigit(bsUrl[i + 1]) && F
X_IsXDigit(bsUrl[i + 2])) { | 241 rUrl += (FX_HexToI(bsUrl[i + 1]) << 4 | FX_HexToI(bsUrl[i + 2])); |
| 256 rUrl += (FX_HexToI(bsUrl[i + 1]) << 4 | FX_HexToI(bsUrl[i + 2])); | 242 i += 2; |
| 257 i += 2; | 243 } else { |
| 258 } else { | 244 rUrl += bsUrl[i]; |
| 259 rUrl += bsUrl[i]; | 245 } |
| 260 } | 246 } |
| 261 } | 247 return CFX_WideString::FromLocal(rUrl); |
| 262 return CFX_WideString::FromLocal(rUrl); | 248 } |
| 263 } | 249 CFX_ByteString FX_EncodeURI(const CFX_WideString& wsURI) { |
| 264 CFX_ByteString FX_EncodeURI(const CFX_WideString& wsURI) | 250 const char arDigits[] = "0123456789ABCDEF"; |
| 265 { | 251 CFX_ByteString rURI; |
| 266 const char arDigits[] = "0123456789ABCDEF"; | 252 CFX_ByteString bsUri = wsURI.UTF8Encode(); |
| 267 CFX_ByteString rURI; | 253 int nLength = bsUri.GetLength(); |
| 268 CFX_ByteString bsUri = wsURI.UTF8Encode(); | 254 for (int i = 0; i < nLength; i++) { |
| 269 int nLength = bsUri.GetLength(); | 255 uint8_t code = bsUri.GetAt(i); |
| 270 for (int i = 0; i < nLength; i++) { | 256 if (code > 0x7F || url_encodeTable[code] == 1) { |
| 271 uint8_t code = bsUri.GetAt(i); | 257 rURI += '%'; |
| 272 if (code > 0x7F || url_encodeTable[code] == 1) { | 258 rURI += arDigits[code >> 4]; |
| 273 rURI += '%'; | 259 rURI += arDigits[code & 0x0F]; |
| 274 rURI += arDigits[code >> 4]; | 260 } else { |
| 275 rURI += arDigits[code & 0x0F]; | 261 rURI += code; |
| 276 } else { | 262 } |
| 277 rURI += code; | 263 } |
| 278 } | 264 return rURI; |
| 279 } | 265 } |
| 280 return rURI; | 266 CFX_WideString FX_DecodeURI(const CFX_ByteString& bsURI) { |
| 281 } | 267 CFX_ByteString rURI; |
| 282 CFX_WideString FX_DecodeURI(const CFX_ByteString& bsURI) | 268 int nLength = bsURI.GetLength(); |
| 283 { | 269 for (int i = 0; i < nLength; i++) { |
| 284 CFX_ByteString rURI; | 270 if (i < nLength - 2 && bsURI[i] == '%' && FX_IsXDigit(bsURI[i + 1]) && |
| 285 int nLength = bsURI.GetLength(); | 271 FX_IsXDigit(bsURI[i + 2])) { |
| 286 for (int i = 0; i < nLength; i++) { | 272 rURI += (FX_HexToI(bsURI[i + 1]) << 4 | FX_HexToI(bsURI[i + 2])); |
| 287 if (i < nLength - 2 && bsURI[i] == '%' && FX_IsXDigit(bsURI[i + 1]) && F
X_IsXDigit(bsURI[i + 2])) { | 273 i += 2; |
| 288 rURI += (FX_HexToI(bsURI[i + 1]) << 4 | FX_HexToI(bsURI[i + 2])); | 274 } else { |
| 289 i += 2; | 275 rURI += bsURI[i]; |
| 290 } else { | 276 } |
| 291 rURI += bsURI[i]; | 277 } |
| 292 } | 278 return CFX_WideString::FromUTF8(rURI, rURI.GetLength()); |
| 293 } | 279 } |
| 294 return CFX_WideString::FromUTF8(rURI, rURI.GetLength()); | 280 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 295 } | 281 class CFindFileData { |
| 296 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 282 public: |
| 297 class CFindFileData | 283 virtual ~CFindFileData() {} |
| 298 { | 284 HANDLE m_Handle; |
| 299 public: | 285 FX_BOOL m_bEnd; |
| 300 virtual ~CFindFileData() {} | |
| 301 HANDLE» » » » m_Handle; | |
| 302 FX_BOOL» » » » m_bEnd; | |
| 303 }; | 286 }; |
| 304 class CFindFileDataA : public CFindFileData | 287 class CFindFileDataA : public CFindFileData { |
| 305 { | 288 public: |
| 306 public: | 289 virtual ~CFindFileDataA() {} |
| 307 virtual ~CFindFileDataA() {} | 290 WIN32_FIND_DATAA m_FindData; |
| 308 WIN32_FIND_DATAA» m_FindData; | |
| 309 }; | 291 }; |
| 310 class CFindFileDataW : public CFindFileData | 292 class CFindFileDataW : public CFindFileData { |
| 311 { | 293 public: |
| 312 public: | 294 virtual ~CFindFileDataW() {} |
| 313 virtual ~CFindFileDataW() {} | 295 WIN32_FIND_DATAW m_FindData; |
| 314 WIN32_FIND_DATAW» m_FindData; | |
| 315 }; | 296 }; |
| 316 #endif | 297 #endif |
| 317 void* FX_OpenFolder(const FX_CHAR* path) | 298 void* FX_OpenFolder(const FX_CHAR* path) { |
| 318 { | |
| 319 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 299 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 320 #ifndef _WIN32_WCE | 300 #ifndef _WIN32_WCE |
| 321 CFindFileDataA* pData = new CFindFileDataA; | 301 CFindFileDataA* pData = new CFindFileDataA; |
| 322 #ifdef _FX_WINAPI_PARTITION_DESKTOP_ | 302 #ifdef _FX_WINAPI_PARTITION_DESKTOP_ |
| 323 pData->m_Handle = FindFirstFileA(CFX_ByteString(path) + "/*.*", &pData->m_Fi
ndData); | 303 pData->m_Handle = |
| 324 #else | 304 FindFirstFileA(CFX_ByteString(path) + "/*.*", &pData->m_FindData); |
| 325 pData->m_Handle = FindFirstFileExA(CFX_ByteString(path) + "/*.*", FindExInfo
Standard, &pData->m_FindData, FindExSearchNameMatch, NULL, 0); | 305 #else |
| 326 #endif | 306 pData->m_Handle = |
| 327 #else | 307 FindFirstFileExA(CFX_ByteString(path) + "/*.*", FindExInfoStandard, |
| 328 CFindFileDataW* pData = new CFindFileDataW; | 308 &pData->m_FindData, FindExSearchNameMatch, NULL, 0); |
| 329 pData->m_Handle = FindFirstFileW(CFX_WideString::FromLocal(path) + L"/*.*",
&pData->m_FindData); | 309 #endif |
| 330 #endif | 310 #else |
| 331 if (pData->m_Handle == INVALID_HANDLE_VALUE) { | 311 CFindFileDataW* pData = new CFindFileDataW; |
| 332 delete pData; | 312 pData->m_Handle = FindFirstFileW(CFX_WideString::FromLocal(path) + L"/*.*", |
| 333 return NULL; | 313 &pData->m_FindData); |
| 334 } | 314 #endif |
| 335 pData->m_bEnd = FALSE; | 315 if (pData->m_Handle == INVALID_HANDLE_VALUE) { |
| 336 return pData; | 316 delete pData; |
| 337 #else | 317 return NULL; |
| 338 DIR* dir = opendir(path); | 318 } |
| 339 return dir; | 319 pData->m_bEnd = FALSE; |
| 340 #endif | 320 return pData; |
| 341 } | 321 #else |
| 342 void* FX_OpenFolder(const FX_WCHAR* path) | 322 DIR* dir = opendir(path); |
| 343 { | 323 return dir; |
| 344 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 324 #endif |
| 345 CFindFileDataW* pData = new CFindFileDataW; | 325 } |
| 326 void* FX_OpenFolder(const FX_WCHAR* path) { |
| 327 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 328 CFindFileDataW* pData = new CFindFileDataW; |
| 346 #ifdef _FX_WINAPI_PARTITION_DESKTOP_ | 329 #ifdef _FX_WINAPI_PARTITION_DESKTOP_ |
| 347 pData->m_Handle = FindFirstFileW((CFX_WideString(path) + L"/*.*").c_str(), &
pData->m_FindData); | 330 pData->m_Handle = FindFirstFileW((CFX_WideString(path) + L"/*.*").c_str(), |
| 348 #else | 331 &pData->m_FindData); |
| 349 pData->m_Handle = FindFirstFileExW((CFX_WideString(path) + L"/*.*").c_str(),
FindExInfoStandard, &pData->m_FindData, FindExSearchNameMatch, NULL, 0); | 332 #else |
| 350 #endif | 333 pData->m_Handle = FindFirstFileExW((CFX_WideString(path) + L"/*.*").c_str(), |
| 351 if (pData->m_Handle == INVALID_HANDLE_VALUE) { | 334 FindExInfoStandard, &pData->m_FindData, |
| 352 delete pData; | 335 FindExSearchNameMatch, NULL, 0); |
| 353 return NULL; | 336 #endif |
| 354 } | 337 if (pData->m_Handle == INVALID_HANDLE_VALUE) { |
| 355 pData->m_bEnd = FALSE; | 338 delete pData; |
| 356 return pData; | 339 return NULL; |
| 357 #else | 340 } |
| 358 DIR* dir = opendir(CFX_ByteString::FromUnicode(path)); | 341 pData->m_bEnd = FALSE; |
| 359 return dir; | 342 return pData; |
| 360 #endif | 343 #else |
| 361 } | 344 DIR* dir = opendir(CFX_ByteString::FromUnicode(path)); |
| 362 FX_BOOL FX_GetNextFile(void* handle, CFX_ByteString& filename, FX_BOOL& bFolder) | 345 return dir; |
| 363 { | 346 #endif |
| 364 if (handle == NULL) { | 347 } |
| 365 return FALSE; | 348 FX_BOOL FX_GetNextFile(void* handle, |
| 366 } | 349 CFX_ByteString& filename, |
| 350 FX_BOOL& bFolder) { |
| 351 if (handle == NULL) { |
| 352 return FALSE; |
| 353 } |
| 367 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 354 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 368 #ifndef _WIN32_WCE | 355 #ifndef _WIN32_WCE |
| 369 CFindFileDataA* pData = (CFindFileDataA*)handle; | 356 CFindFileDataA* pData = (CFindFileDataA*)handle; |
| 370 if (pData->m_bEnd) { | 357 if (pData->m_bEnd) { |
| 371 return FALSE; | 358 return FALSE; |
| 372 } | 359 } |
| 373 filename = pData->m_FindData.cFileName; | 360 filename = pData->m_FindData.cFileName; |
| 374 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; | 361 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; |
| 375 if (!FindNextFileA(pData->m_Handle, &pData->m_FindData)) { | 362 if (!FindNextFileA(pData->m_Handle, &pData->m_FindData)) { |
| 376 pData->m_bEnd = TRUE; | 363 pData->m_bEnd = TRUE; |
| 377 } | 364 } |
| 378 return TRUE; | 365 return TRUE; |
| 379 #else | 366 #else |
| 380 CFindFileDataW* pData = (CFindFileDataW*)handle; | 367 CFindFileDataW* pData = (CFindFileDataW*)handle; |
| 381 if (pData->m_bEnd) { | 368 if (pData->m_bEnd) { |
| 382 return FALSE; | 369 return FALSE; |
| 383 } | 370 } |
| 384 filename = CFX_ByteString::FromUnicode(pData->m_FindData.cFileName); | 371 filename = CFX_ByteString::FromUnicode(pData->m_FindData.cFileName); |
| 385 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; | 372 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; |
| 386 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { | 373 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { |
| 387 pData->m_bEnd = TRUE; | 374 pData->m_bEnd = TRUE; |
| 388 } | 375 } |
| 389 return TRUE; | 376 return TRUE; |
| 390 #endif | 377 #endif |
| 391 #elif defined(__native_client__) | 378 #elif defined(__native_client__) |
| 392 abort(); | 379 abort(); |
| 393 return FALSE; | 380 return FALSE; |
| 394 #else | 381 #else |
| 395 struct dirent *de = readdir((DIR*)handle); | 382 struct dirent* de = readdir((DIR*)handle); |
| 396 if (de == NULL) { | 383 if (de == NULL) { |
| 397 return FALSE; | 384 return FALSE; |
| 398 } | 385 } |
| 399 filename = de->d_name; | 386 filename = de->d_name; |
| 400 bFolder = de->d_type == DT_DIR; | 387 bFolder = de->d_type == DT_DIR; |
| 401 return TRUE; | 388 return TRUE; |
| 402 #endif | 389 #endif |
| 403 } | 390 } |
| 404 FX_BOOL FX_GetNextFile(void* handle, CFX_WideString& filename, FX_BOOL& bFolder) | 391 FX_BOOL FX_GetNextFile(void* handle, |
| 405 { | 392 CFX_WideString& filename, |
| 406 if (handle == NULL) { | 393 FX_BOOL& bFolder) { |
| 407 return FALSE; | 394 if (handle == NULL) { |
| 408 } | 395 return FALSE; |
| 409 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 396 } |
| 410 CFindFileDataW* pData = (CFindFileDataW*)handle; | 397 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 411 if (pData->m_bEnd) { | 398 CFindFileDataW* pData = (CFindFileDataW*)handle; |
| 412 return FALSE; | 399 if (pData->m_bEnd) { |
| 413 } | 400 return FALSE; |
| 414 filename = pData->m_FindData.cFileName; | 401 } |
| 415 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; | 402 filename = pData->m_FindData.cFileName; |
| 416 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { | 403 bFolder = pData->m_FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; |
| 417 pData->m_bEnd = TRUE; | 404 if (!FindNextFileW(pData->m_Handle, &pData->m_FindData)) { |
| 418 } | 405 pData->m_bEnd = TRUE; |
| 419 return TRUE; | 406 } |
| 407 return TRUE; |
| 420 #elif defined(__native_client__) | 408 #elif defined(__native_client__) |
| 421 abort(); | 409 abort(); |
| 422 return FALSE; | 410 return FALSE; |
| 423 #else | 411 #else |
| 424 struct dirent *de = readdir((DIR*)handle); | 412 struct dirent* de = readdir((DIR*)handle); |
| 425 if (de == NULL) { | 413 if (de == NULL) { |
| 426 return FALSE; | 414 return FALSE; |
| 427 } | 415 } |
| 428 filename = CFX_WideString::FromLocal(de->d_name); | 416 filename = CFX_WideString::FromLocal(de->d_name); |
| 429 bFolder = de->d_type == DT_DIR; | 417 bFolder = de->d_type == DT_DIR; |
| 430 return TRUE; | 418 return TRUE; |
| 431 #endif | 419 #endif |
| 432 } | 420 } |
| 433 void FX_CloseFolder(void* handle) | 421 void FX_CloseFolder(void* handle) { |
| 434 { | 422 if (handle == NULL) { |
| 435 if (handle == NULL) { | 423 return; |
| 436 return; | 424 } |
| 437 } | 425 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 438 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 426 CFindFileData* pData = (CFindFileData*)handle; |
| 439 CFindFileData* pData = (CFindFileData*)handle; | 427 FindClose(pData->m_Handle); |
| 440 FindClose(pData->m_Handle); | 428 delete pData; |
| 441 delete pData; | 429 #else |
| 442 #else | 430 closedir((DIR*)handle); |
| 443 closedir((DIR*)handle); | 431 #endif |
| 444 #endif | 432 } |
| 445 } | 433 FX_WCHAR FX_GetFolderSeparator() { |
| 446 FX_WCHAR FX_GetFolderSeparator() | 434 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 447 { | 435 return '\\'; |
| 448 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 436 #else |
| 449 return '\\'; | 437 return '/'; |
| 450 #else | 438 #endif |
| 451 return '/'; | 439 } |
| 452 #endif | 440 |
| 453 } | 441 CFX_Matrix_3by3 CFX_Matrix_3by3::Inverse() { |
| 454 | 442 FX_FLOAT det = |
| 455 CFX_Matrix_3by3 CFX_Matrix_3by3::Inverse() | 443 a * (e * i - f * h) - b * (i * d - f * g) + c * (d * h - e * g); |
| 456 { | 444 if (FXSYS_fabs(det) < 0.0000001) |
| 457 FX_FLOAT det = a*(e*i - f*h) - b*(i*d - f*g) + c*(d*h - e*g); | 445 return CFX_Matrix_3by3(); |
| 458 if (FXSYS_fabs(det) < 0.0000001) | 446 |
| 459 return CFX_Matrix_3by3(); | 447 return CFX_Matrix_3by3( |
| 460 | 448 (e * i - f * h) / det, -(b * i - c * h) / det, (b * f - c * e) / det, |
| 461 return CFX_Matrix_3by3( | 449 -(d * i - f * g) / det, (a * i - c * g) / det, -(a * f - c * d) / det, |
| 462 (e*i - f*h) / det, | 450 (d * h - e * g) / det, -(a * h - b * g) / det, (a * e - b * d) / det); |
| 463 -(b*i - c*h) / det, | 451 } |
| 464 (b*f - c*e) / det, | 452 |
| 465 -(d*i - f*g) / det, | 453 CFX_Matrix_3by3 CFX_Matrix_3by3::Multiply(const CFX_Matrix_3by3& m) { |
| 466 (a*i - c*g) / det, | 454 return CFX_Matrix_3by3( |
| 467 -(a*f - c*d) / det, | 455 a * m.a + b * m.d + c * m.g, a * m.b + b * m.e + c * m.h, |
| 468 (d*h - e*g) / det, | 456 a * m.c + b * m.f + c * m.i, d * m.a + e * m.d + f * m.g, |
| 469 -(a*h - b*g) / det, | 457 d * m.b + e * m.e + f * m.h, d * m.c + e * m.f + f * m.i, |
| 470 (a*e - b*d) / det | 458 g * m.a + h * m.d + i * m.g, g * m.b + h * m.e + i * m.h, |
| 471 ); | 459 g * m.c + h * m.f + i * m.i); |
| 472 } | 460 } |
| 473 | 461 |
| 474 CFX_Matrix_3by3 CFX_Matrix_3by3::Multiply(const CFX_Matrix_3by3 &m) | 462 CFX_Vector_3by1 CFX_Matrix_3by3::TransformVector(const CFX_Vector_3by1& v) { |
| 475 { | 463 return CFX_Vector_3by1(a * v.a + b * v.b + c * v.c, |
| 476 return CFX_Matrix_3by3( | 464 d * v.a + e * v.b + f * v.c, |
| 477 a*m.a + b*m.d + c*m.g, | 465 g * v.a + h * v.b + i * v.c); |
| 478 a*m.b + b*m.e + c*m.h, | 466 } |
| 479 a*m.c + b*m.f + c*m.i, | |
| 480 d*m.a + e*m.d + f*m.g, | |
| 481 d*m.b + e*m.e + f*m.h, | |
| 482 d*m.c + e*m.f + f*m.i, | |
| 483 g*m.a + h*m.d + i*m.g, | |
| 484 g*m.b + h*m.e + i*m.h, | |
| 485 g*m.c + h*m.f + i*m.i | |
| 486 ); | |
| 487 } | |
| 488 | |
| 489 CFX_Vector_3by1 CFX_Matrix_3by3::TransformVector(const CFX_Vector_3by1 &v) | |
| 490 { | |
| 491 return CFX_Vector_3by1( | |
| 492 a * v.a + b * v.b + c * v.c, | |
| 493 d * v.a + e * v.b + f * v.c, | |
| 494 g * v.a + h * v.b + i * v.c | |
| 495 ); | |
| 496 } | |
| OLD | NEW |