Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | ******************************************************************************* |
michael@0 | 3 | * Copyright (C) 2009-2010, International Business Machines Corporation and |
michael@0 | 4 | * others. All Rights Reserved. |
michael@0 | 5 | ******************************************************************************* |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #include "unicode/utypes.h" |
michael@0 | 9 | |
michael@0 | 10 | #if !UCONFIG_NO_FORMATTING |
michael@0 | 11 | |
michael@0 | 12 | #include "fphdlimp.h" |
michael@0 | 13 | #include "uvectr32.h" |
michael@0 | 14 | |
michael@0 | 15 | U_NAMESPACE_BEGIN |
michael@0 | 16 | |
michael@0 | 17 | // utility FieldPositionHandler |
michael@0 | 18 | // base class, null implementation |
michael@0 | 19 | |
michael@0 | 20 | FieldPositionHandler::~FieldPositionHandler() { |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | void |
michael@0 | 24 | FieldPositionHandler::addAttribute(int32_t, int32_t, int32_t) { |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | void |
michael@0 | 28 | FieldPositionHandler::shiftLast(int32_t) { |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | UBool |
michael@0 | 32 | FieldPositionHandler::isRecording(void) { |
michael@0 | 33 | return FALSE; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | |
michael@0 | 37 | // utility subclass FieldPositionOnlyHandler |
michael@0 | 38 | |
michael@0 | 39 | FieldPositionOnlyHandler::FieldPositionOnlyHandler(FieldPosition& _pos) |
michael@0 | 40 | : pos(_pos) { |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | FieldPositionOnlyHandler::~FieldPositionOnlyHandler() { |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | void |
michael@0 | 47 | FieldPositionOnlyHandler::addAttribute(int32_t id, int32_t start, int32_t limit) { |
michael@0 | 48 | if (pos.getField() == id) { |
michael@0 | 49 | pos.setBeginIndex(start); |
michael@0 | 50 | pos.setEndIndex(limit); |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | void |
michael@0 | 55 | FieldPositionOnlyHandler::shiftLast(int32_t delta) { |
michael@0 | 56 | if (delta != 0 && pos.getField() != FieldPosition::DONT_CARE && pos.getBeginIndex() != -1) { |
michael@0 | 57 | pos.setBeginIndex(delta + pos.getBeginIndex()); |
michael@0 | 58 | pos.setEndIndex(delta + pos.getEndIndex()); |
michael@0 | 59 | } |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | UBool |
michael@0 | 63 | FieldPositionOnlyHandler::isRecording(void) { |
michael@0 | 64 | return pos.getField() != FieldPosition::DONT_CARE; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | |
michael@0 | 68 | // utility subclass FieldPositionIteratorHandler |
michael@0 | 69 | |
michael@0 | 70 | FieldPositionIteratorHandler::FieldPositionIteratorHandler(FieldPositionIterator* posIter, |
michael@0 | 71 | UErrorCode& _status) |
michael@0 | 72 | : iter(posIter), vec(NULL), status(_status) { |
michael@0 | 73 | if (iter && U_SUCCESS(status)) { |
michael@0 | 74 | vec = new UVector32(status); |
michael@0 | 75 | } |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | FieldPositionIteratorHandler::~FieldPositionIteratorHandler() { |
michael@0 | 79 | // setData adopts the vec regardless of status, so it's safe to null it |
michael@0 | 80 | if (iter) { |
michael@0 | 81 | iter->setData(vec, status); |
michael@0 | 82 | } |
michael@0 | 83 | // if iter is null, we never allocated vec, so no need to free it |
michael@0 | 84 | vec = NULL; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | void |
michael@0 | 88 | FieldPositionIteratorHandler::addAttribute(int32_t id, int32_t start, int32_t limit) { |
michael@0 | 89 | if (iter && U_SUCCESS(status) && start < limit) { |
michael@0 | 90 | int32_t size = vec->size(); |
michael@0 | 91 | vec->addElement(id, status); |
michael@0 | 92 | vec->addElement(start, status); |
michael@0 | 93 | vec->addElement(limit, status); |
michael@0 | 94 | if (!U_SUCCESS(status)) { |
michael@0 | 95 | vec->setSize(size); |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | void |
michael@0 | 101 | FieldPositionIteratorHandler::shiftLast(int32_t delta) { |
michael@0 | 102 | if (U_SUCCESS(status) && delta != 0) { |
michael@0 | 103 | int32_t i = vec->size(); |
michael@0 | 104 | if (i > 0) { |
michael@0 | 105 | --i; |
michael@0 | 106 | vec->setElementAt(delta + vec->elementAti(i), i); |
michael@0 | 107 | --i; |
michael@0 | 108 | vec->setElementAt(delta + vec->elementAti(i), i); |
michael@0 | 109 | } |
michael@0 | 110 | } |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | UBool |
michael@0 | 114 | FieldPositionIteratorHandler::isRecording(void) { |
michael@0 | 115 | return U_SUCCESS(status); |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | U_NAMESPACE_END |
michael@0 | 119 | |
michael@0 | 120 | #endif /* !UCONFIG_NO_FORMATTING */ |