Skip to content

Commit

Permalink
Specification of pointer usage
Browse files Browse the repository at this point in the history
Avoid C-style casts when possible.

Change-Id: I8e86eb8c439b456da41d52a5666190330edeeda2
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
uos-hl committed Jan 29, 2021
1 parent 29a58af commit 693aa08
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/corelib/text/qunicodetools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ static th_next_cell_def th_next_cell = nullptr;
static int init_libthai() {
static bool initialized = false;
if (!initialized && (!th_brk || !th_next_cell)) {
th_brk = (th_brk_def) QLibrary::resolve(QLatin1String("thai"), (int)LIBTHAI_MAJOR, "th_brk");
th_brk = reinterpret_cast<th_brk_def>(QLibrary::resolve(QLatin1String("thai"), static_cast<int>(LIBTHAI_MAJOR), "th_brk"));
th_next_cell = (th_next_cell_def)QLibrary::resolve(QLatin1String("thai"), LIBTHAI_MAJOR, "th_next_cell");
initialized = true;
}
Expand All @@ -1342,7 +1342,7 @@ static int init_libthai() {
static void to_tis620(const char16_t *string, qsizetype len, char *cstr)
{
qsizetype i;
unsigned char *result = (unsigned char *)cstr;
unsigned char *result = reinterpret_cast<unsigned char *>(cstr);

for (i = 0; i < len; ++i) {
if (string[i] <= 0xa0)
Expand Down Expand Up @@ -1373,7 +1373,7 @@ static void thaiAssignAttributes(const char16_t *string, qsizetype len, QCharAtt
return ;

if (len >= 128)
cstr = (char *)malloc(len*sizeof(char) + 1);
cstr = static_cast<char *>(malloc (len * sizeof(char) + 1));

to_tis620(string, len, cstr);

Expand All @@ -1385,7 +1385,7 @@ static void thaiAssignAttributes(const char16_t *string, qsizetype len, QCharAtt
}

if (len > 128) {
break_positions = (int*) malloc (sizeof(int) * len);
break_positions = static_cast<int *>(malloc (sizeof(int) * len));
memset (break_positions, 0, sizeof(int) * len);
brp_size = len;
}
Expand All @@ -1398,7 +1398,7 @@ static void thaiAssignAttributes(const char16_t *string, qsizetype len, QCharAtt
attributes[0].wordBreak = true;
attributes[0].wordStart = true;
attributes[0].wordEnd = false;
numbreaks = th_brk((const unsigned char *)cstr, break_positions, brp_size);
numbreaks = th_brk(reinterpret_cast<const unsigned char *>(cstr), break_positions, brp_size);
for (i = 0; i < numbreaks; ++i) {
attributes[break_positions[i]].wordBreak = true;
attributes[break_positions[i]].wordStart = true;
Expand All @@ -1415,14 +1415,15 @@ static void thaiAssignAttributes(const char16_t *string, qsizetype len, QCharAtt
/* manage grapheme boundaries */
i = 0;
while (i < len) {
cell_length = (uint)(th_next_cell((const unsigned char *)cstr + i, len - i, &tis_cell, true));
cell_length = static_cast<uint>(th_next_cell(reinterpret_cast<const unsigned char *>(cstr) + i, len - i, &tis_cell, true));


attributes[i].graphemeBoundary = true;
for (j = 1; j < cell_length; j++)
attributes[i + j].graphemeBoundary = false;

/* Set graphemeBoundary for SARA AM */
if (cstr[i + cell_length - 1] == (char)0xd3)
if (cstr[i + cell_length - 1] == static_cast<char>(0xd3))
attributes[i + cell_length - 1].graphemeBoundary = true;

i += cell_length;
Expand Down

0 comments on commit 693aa08

Please sign in to comment.