aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZufu Liu <unknown>2021-07-03 14:47:54 +1000
committerZufu Liu <unknown>2021-07-03 14:47:54 +1000
commit67d41ce2237e39ea3be7932659fe04f263c82b24 (patch)
tree5883fd367b299b34c0c65f0e4cba80353af28996
parenta2d23bd463e65f532301b682b64cd02b8a57716b (diff)
downloadscintilla-mirror-67d41ce2237e39ea3be7932659fe04f263c82b24.tar.gz
Feature [feature-requests:#1408] Avoid sprintf for hexadecimal character blobs.
-rw-r--r--src/EditView.cxx9
-rw-r--r--src/EditView.h1
-rw-r--r--src/Editor.cxx8
3 files changed, 13 insertions, 5 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx
index a71f385e7..e4b0fa5d9 100644
--- a/src/EditView.cxx
+++ b/src/EditView.cxx
@@ -170,6 +170,13 @@ void DrawStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, PRec
}
}
+void Hexits(char *hexits, int ch) noexcept {
+ hexits[0] = 'x';
+ hexits[1] = "0123456789ABCDEF"[ch / 0x10];
+ hexits[2] = "0123456789ABCDEF"[ch % 0x10];
+ hexits[3] = 0;
+}
+
}
EditView::EditView() {
@@ -1040,7 +1047,7 @@ void EditView::DrawEOL(Surface *surface, const EditModel &model, const ViewStyle
if (UTF8IsAscii(chEOL)) {
ctrlChar = ControlCharacterString(chEOL);
} else {
- sprintf(hexits, "x%2X", chEOL);
+ Hexits(hexits, chEOL);
ctrlChar = hexits;
}
}
diff --git a/src/EditView.h b/src/EditView.h
index 148d6e52d..bac59ed31 100644
--- a/src/EditView.h
+++ b/src/EditView.h
@@ -40,6 +40,7 @@ void DrawTextNoClipPhase(Surface *surface, PRectangle rc, const Style &style, XY
std::string_view text, DrawPhase phase);
void DrawStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, PRectangle rcText,
const StyledText &st, size_t start, size_t length, DrawPhase phase);
+void Hexits(char *hexits, int ch) noexcept;
typedef void (*DrawTabArrowFn)(Surface *surface, PRectangle rcTab, int ymid,
const ViewStyle &vsDraw, Stroke stroke);
diff --git a/src/Editor.cxx b/src/Editor.cxx
index 71aaeae53..d01eb0cdf 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -247,8 +247,8 @@ void Editor::SetRepresentations() {
if (IsUnicodeMode()) {
for (int k=0x80; k < 0x100; k++) {
const char hiByte[2] = { static_cast<char>(k), 0 };
- char hexits[5]; // Really only needs 4 but that causes warning from gcc 7.1
- sprintf(hexits, "x%2X", k);
+ char hexits[4];
+ Hexits(hexits, k);
reprs.SetRepresentation(hiByte, hexits);
}
} else if (pdoc->dbcsCodePage) {
@@ -257,8 +257,8 @@ void Editor::SetRepresentations() {
const char ch = static_cast<char>(k);
if (pdoc->IsDBCSLeadByteNoExcept(ch) || pdoc->IsDBCSLeadByteInvalid(ch)) {
const char hiByte[2] = { ch, 0 };
- char hexits[5]; // Really only needs 4 but that causes warning from gcc 7.1
- sprintf(hexits, "x%2X", k);
+ char hexits[4];
+ Hexits(hexits, k);
reprs.SetRepresentation(hiByte, hexits);
}
}