Created
August 11, 2016 17:51
-
-
Save HalCanary/6f18648a96126d349c15822b45c9361f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2016 Google Inc. | |
* | |
* Use of this source code is governed by a BSD-style license that can be | |
* found in the LICENSE file. | |
*/ | |
class UnicodeIterator { | |
public: | |
UnicodeIterator(const SkPaint& paint, const void* txt, size_t len) | |
: fBegin((const char*)txt) | |
, fEnd((const char*)txt + len) | |
, fEncoding(encoding) {} | |
class ConstIter { | |
public: | |
void operator++() { | |
if (fPtr == fEnd) { | |
return; | |
} | |
switch (fPaint.getTextEncoding()) { | |
case SkPaint::kUTF8_TextEncoding: | |
fUnichar = SkUTF8_NextUnichar(&fPtr); | |
break; | |
case SkPaint::kUTF16_TextEncoding: | |
fUnichar = SkUTF16_NextUnichar((const uint16_t**)&ptr); | |
break; | |
case SkPaint::kUTF32_TextEncoding: | |
fUnichar = *(const SkUnichar*)fPtr; | |
fPtr += 4; | |
break; | |
case SkPaint::kGlyphID_TextEncoding: | |
fPaint.glyphsToUnichars((const uint16_t*)fPtr, 2, &fUnichar); | |
fPtr += 2; | |
break; | |
default: | |
SkASSERT(false); | |
} | |
if (fPtr > fEnd) { | |
fPtr = fEnd; | |
} | |
} | |
SkUnichar operator*() const { return fUnichar; } | |
bool operator!=(const ConstIter& rhs) const { return fPtr != rhs.fPtr; } | |
ConstIter(const char* p, const char* e, const SkPaint& p) : | |
fPtr(p), fEnd(e), fPaint(p), fUnichar(0) { ++*this; } | |
private: | |
const char* fPtr; | |
const char* const fEnd; | |
SkUnichar fUnichar; | |
const SkPaint& fPaint; | |
}; | |
ConstIter begin() const { return ConstIter(fBegin, fEnd, fPaint); } | |
ConstIter end() const { return ConstIter(fEnd, fEnd, fPaint); } | |
private: | |
const char* const fBegin; | |
const char* const fEnd; | |
const SkPaint& fPaint; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment