summaryrefslogtreecommitdiff
path: root/test/utf8.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'test/utf8.cxx')
-rw-r--r--test/utf8.cxx44
1 files changed, 20 insertions, 24 deletions
diff --git a/test/utf8.cxx b/test/utf8.cxx
index e47317026..d5e1758a6 100644
--- a/test/utf8.cxx
+++ b/test/utf8.cxx
@@ -74,7 +74,7 @@ static void cb_hide_all(Fl_Widget*, void*) {
Class for displaying sample fonts.
*/
class FontDisplay : public Fl_Widget {
- void draw(void) override;
+ void draw(void);
public:
int font, size;
@@ -455,7 +455,7 @@ class right_left_input : public Fl_Input {
public:
right_left_input(int x, int y, int w, int h)
: Fl_Input(x, y, w, h) {}
- void draw() override {
+ void draw() {
if (type() == FL_HIDDEN_INPUT)
return;
Fl_Boxtype b = box();
@@ -505,7 +505,7 @@ public:
"Only the first Unicode code point will be displayed.\n"
"Example: U+1F308 '🌈' 0x{f0,9f,8c,88}");
}
- int handle(int event) override {
+ int handle(int event) {
switch (event) {
case FL_DND_ENTER: return 1;
case FL_DND_DRAG: return 1;
@@ -513,7 +513,6 @@ public:
case FL_PASTE: {
int i, n;
const char *t = Fl::event_text();
- char temp[10];
unsigned int ucode = fl_utf8decode(t, t + Fl::event_length(), &n);
if (n == 0) {
value("");
@@ -524,35 +523,32 @@ public:
// - length = 30: "U+1F308 '🌈' 0x{f0,9f,8c,88}" -- UTF-8 encoding = 4 bytes
// - length = 31: "U+10FFFF '􏿿' 0x{f4,8f,bf,bf}" -- UTF-8 encoding = 4 bytes
//
- static const size_t max_size = 32;
// begin with first Unicode code point of Fl::event_text() in single quotes
int tl = fl_utf8len(t[0]);
if (tl < 1)
tl = 1;
- std::string buffer;
- buffer.reserve(max_size);
+ char buffer[64];
+ char *p = buffer;
// add Unicode code point: "U+0000" - "U+10FFFF" (4-6 hex digits)
- buffer += "U+";
- snprintf(temp, 9, "%04X", ucode);
- buffer += temp;
+ p += sprintf(p, "U+%04X '", ucode);
// add Unicode character in quotes
- buffer += " '";
- buffer += std::string(t, tl);
- buffer += "'";
+ memcpy(p, t, tl);
+ p += tl;
+ *p++ = '\'';
// add hex UTF-8 codes, format: "0xab" or "0x{de,ad,be,ef}"
- buffer += " 0x";
+ p += sprintf(p, " 0x");
if (n > 1)
- buffer += "{";
+ *p++ = '{';
for (i = 0; i < n; i++) {
if (i > 0)
- buffer += ',';
- snprintf(temp, 9, "%02x", (unsigned char)t[i]);
- buffer += temp;
+ *p++ = ',';
+ p += sprintf(p, "%02x", (unsigned char)t[i]);
}
if (n > 1)
- buffer += "}";
- value(buffer.c_str());
- printf("size: %lu\n", buffer.size()); fflush(stdout);
+ *p++ = '}';
+ *p = '\0';
+ value(buffer);
+ printf("size: %lu\n", (unsigned long)(p - buffer)); fflush(stdout);
}
return 1;
}
@@ -578,7 +574,7 @@ Fl_Input *iw[20]; // global widget pointers
Fl_Scroll *make_scroll(int off) {
- auto scroll = new Fl_Scroll(IW + 10, 0, SW, WH);
+ Fl_Scroll *scroll = new Fl_Scroll(IW + 10, 0, SW, WH);
int end_list = 0x10000 / 16;
if (off > 2) {
@@ -638,7 +634,7 @@ Fl_Scroll *make_scroll(int off) {
Fl_Grid *make_grid(int off) {
- auto grid = new Fl_Grid(0, 0, WW, WH); // full window size
+ Fl_Grid *grid = new Fl_Grid(0, 0, WW, WH); // full window size
grid->layout(10, 2, 5, 5); // rows, cols, margin, gap
int col_weights[] = { 100, 0 }; // resize only first column
grid->col_weight(col_weights, 2);
@@ -725,7 +721,7 @@ int main(int argc, char** argv) {
main_win = new Fl_Double_Window (WW, WH, "Unicode Display");
main_win->begin();
- auto grid = make_grid(off); // make a grid layout of widgets
+ Fl_Grid *grid = make_grid(off); // make a grid layout of widgets
// populate the grid's contents