LEFT | RIGHT |
(no file at all) | |
1 // © 2016 and later: Unicode, Inc. and others. | 1 // © 2016 and later: Unicode, Inc. and others. |
2 // License & terms of use: http://www.unicode.org/copyright.html | 2 // License & terms of use: http://www.unicode.org/copyright.html |
3 /* | 3 /* |
4 ********************************************************************** | 4 ********************************************************************** |
5 * Copyright (c) 2004-2016, International Business Machines | 5 * Copyright (c) 2004-2016, International Business Machines |
6 * Corporation and others. All Rights Reserved. | 6 * Corporation and others. All Rights Reserved. |
7 ********************************************************************** | 7 ********************************************************************** |
8 * Author: Alan Liu | 8 * Author: Alan Liu |
9 * Created: April 26, 2004 | 9 * Created: April 26, 2004 |
10 * Since: ICU 3.0 | 10 * Since: ICU 3.0 |
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 if (t < 0) { | 1204 if (t < 0) { |
1205 return t; | 1205 return t; |
1206 } | 1206 } |
1207 int32_t st = binarySearch(gSubTypes, gOffsets[t], gOffsets[t + 1], subtype); | 1207 int32_t st = binarySearch(gSubTypes, gOffsets[t], gOffsets[t + 1], subtype); |
1208 if (st < 0) { | 1208 if (st < 0) { |
1209 return st; | 1209 return st; |
1210 } | 1210 } |
1211 return gIndexes[t] + st - gOffsets[t]; | 1211 return gIndexes[t] + st - gOffsets[t]; |
1212 } | 1212 } |
1213 | 1213 |
1214 MeasureUnit *MeasureUnit::resolveUnitPerUnit( | 1214 MeasureUnit MeasureUnit::resolveUnitPerUnit( |
1215 const MeasureUnit &unit, const MeasureUnit &perUnit) { | 1215 const MeasureUnit &unit, const MeasureUnit &perUnit, bool* isResolved) { |
1216 int32_t unitOffset = unit.getOffset(); | 1216 int32_t unitOffset = unit.getOffset(); |
1217 int32_t perUnitOffset = perUnit.getOffset(); | 1217 int32_t perUnitOffset = perUnit.getOffset(); |
1218 | 1218 |
1219 // binary search for (unitOffset, perUnitOffset) | 1219 // binary search for (unitOffset, perUnitOffset) |
1220 int32_t start = 0; | 1220 int32_t start = 0; |
1221 int32_t end = UPRV_LENGTHOF(unitPerUnitToSingleUnit); | 1221 int32_t end = UPRV_LENGTHOF(unitPerUnitToSingleUnit); |
1222 while (start < end) { | 1222 while (start < end) { |
1223 int32_t mid = (start + end) / 2; | 1223 int32_t mid = (start + end) / 2; |
1224 int32_t *midRow = unitPerUnitToSingleUnit[mid]; | 1224 int32_t *midRow = unitPerUnitToSingleUnit[mid]; |
1225 if (unitOffset < midRow[0]) { | 1225 if (unitOffset < midRow[0]) { |
1226 end = mid; | 1226 end = mid; |
1227 } else if (unitOffset > midRow[0]) { | 1227 } else if (unitOffset > midRow[0]) { |
1228 start = mid + 1; | 1228 start = mid + 1; |
1229 } else if (perUnitOffset < midRow[1]) { | 1229 } else if (perUnitOffset < midRow[1]) { |
1230 end = mid; | 1230 end = mid; |
1231 } else if (perUnitOffset > midRow[1]) { | 1231 } else if (perUnitOffset > midRow[1]) { |
1232 start = mid + 1; | 1232 start = mid + 1; |
1233 } else { | 1233 } else { |
1234 // We found a resolution for our unit / per-unit combo | 1234 // We found a resolution for our unit / per-unit combo |
1235 // return it. | 1235 // return it. |
1236 return new MeasureUnit(midRow[2], midRow[3]); | 1236 *isResolved = true; |
| 1237 return MeasureUnit(midRow[2], midRow[3]); |
1237 } | 1238 } |
1238 } | 1239 } |
1239 return NULL; | 1240 |
| 1241 *isResolved = false; |
| 1242 return MeasureUnit(); |
1240 } | 1243 } |
1241 | 1244 |
1242 MeasureUnit *MeasureUnit::create(int typeId, int subTypeId, UErrorCode &status)
{ | 1245 MeasureUnit *MeasureUnit::create(int typeId, int subTypeId, UErrorCode &status)
{ |
1243 if (U_FAILURE(status)) { | 1246 if (U_FAILURE(status)) { |
1244 return NULL; | 1247 return NULL; |
1245 } | 1248 } |
1246 MeasureUnit *result = new MeasureUnit(typeId, subTypeId); | 1249 MeasureUnit *result = new MeasureUnit(typeId, subTypeId); |
1247 if (result == NULL) { | 1250 if (result == NULL) { |
1248 status = U_MEMORY_ALLOCATION_ERROR; | 1251 status = U_MEMORY_ALLOCATION_ERROR; |
1249 } | 1252 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 fCurrency[0] = 0; | 1291 fCurrency[0] = 0; |
1289 } | 1292 } |
1290 | 1293 |
1291 int32_t MeasureUnit::getOffset() const { | 1294 int32_t MeasureUnit::getOffset() const { |
1292 return gOffsets[fTypeId] + fSubTypeId; | 1295 return gOffsets[fTypeId] + fSubTypeId; |
1293 } | 1296 } |
1294 | 1297 |
1295 U_NAMESPACE_END | 1298 U_NAMESPACE_END |
1296 | 1299 |
1297 #endif /* !UNCONFIG_NO_FORMATTING */ | 1300 #endif /* !UNCONFIG_NO_FORMATTING */ |
LEFT | RIGHT |