Fix const correctness in some functions.

This patch fixes a lot of casts that were unnecessarily removing
`const` from pointer variables.
pull/367/head
Sam Hocevar 2016-10-22 12:54:15 +02:00
parent 2f4166e91d
commit efa53ff480
3 changed files with 28 additions and 28 deletions

View File

@ -510,8 +510,8 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
static int rect_height_compare(const void *a, const void *b)
{
stbrp_rect *p = (stbrp_rect *) a;
stbrp_rect *q = (stbrp_rect *) b;
stbrp_rect const *p = (stbrp_rect const *) a;
stbrp_rect const *q = (stbrp_rect const *) b;
if (p->h > q->h)
return -1;
if (p->h < q->h)
@ -521,8 +521,8 @@ static int rect_height_compare(const void *a, const void *b)
static int rect_width_compare(const void *a, const void *b)
{
stbrp_rect *p = (stbrp_rect *) a;
stbrp_rect *q = (stbrp_rect *) b;
stbrp_rect const *p = (stbrp_rect const *) a;
stbrp_rect const *q = (stbrp_rect const *) b;
if (p->w > q->w)
return -1;
if (p->w < q->w)
@ -532,8 +532,8 @@ static int rect_width_compare(const void *a, const void *b)
static int rect_original_order(const void *a, const void *b)
{
stbrp_rect *p = (stbrp_rect *) a;
stbrp_rect *q = (stbrp_rect *) b;
stbrp_rect const *p = (stbrp_rect const *) a;
stbrp_rect const *q = (stbrp_rect const *) b;
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
}

View File

@ -673,7 +673,7 @@ static int stb_textedit_cut(STB_TEXTEDIT_STRING *str, STB_TexteditState *state)
// API paste: replace existing selection with passed-in text
static int stb_textedit_paste(STB_TEXTEDIT_STRING *str, STB_TexteditState *state, STB_TEXTEDIT_CHARTYPE const *ctext, int len)
{
STB_TEXTEDIT_CHARTYPE *text = (STB_TEXTEDIT_CHARTYPE *) ctext;
STB_TEXTEDIT_CHARTYPE const *text = (STB_TEXTEDIT_CHARTYPE const *) ctext;
// if there's a selection, the paste should delete it
stb_textedit_clamp(str, state);
stb_textedit_delete_selection(str,state);

View File

@ -640,7 +640,7 @@ STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index);
struct stbtt_fontinfo
{
void * userdata;
unsigned char * data; // pointer to .ttf file
unsigned char const * data; // pointer to .ttf file
int fontstart; // offset of start of font
int numGlyphs; // number of glyphs, needed for range checking
@ -964,16 +964,16 @@ typedef int stbtt__test_oversample_pow2[(STBTT_MAX_OVERSAMPLE & (STBTT_MAX_OVERS
// on platforms that don't allow misaligned reads, if we want to allow
// truetype fonts that aren't padded to alignment, define ALLOW_UNALIGNED_TRUETYPE
#define ttBYTE(p) (* (stbtt_uint8 *) (p))
#define ttCHAR(p) (* (stbtt_int8 *) (p))
#define ttBYTE(p) (* (stbtt_uint8 const *) (p))
#define ttCHAR(p) (* (stbtt_int8 const *) (p))
#define ttFixed(p) ttLONG(p)
#if defined(STB_TRUETYPE_BIGENDIAN) && !defined(ALLOW_UNALIGNED_TRUETYPE)
#define ttUSHORT(p) (* (stbtt_uint16 *) (p))
#define ttSHORT(p) (* (stbtt_int16 *) (p))
#define ttULONG(p) (* (stbtt_uint32 *) (p))
#define ttLONG(p) (* (stbtt_int32 *) (p))
#define ttUSHORT(p) (* (stbtt_uint16 const *) (p))
#define ttSHORT(p) (* (stbtt_int16 const *) (p))
#define ttULONG(p) (* (stbtt_uint32 const *) (p))
#define ttLONG(p) (* (stbtt_int32 const *) (p))
#else
@ -998,7 +998,7 @@ static int stbtt__isfont(const stbtt_uint8 *font)
}
// @OPTIMIZE: binary search
static stbtt_uint32 stbtt__find_table(stbtt_uint8 *data, stbtt_uint32 fontstart, const char *tag)
static stbtt_uint32 stbtt__find_table(stbtt_uint8 const *data, stbtt_uint32 fontstart, const char *tag)
{
stbtt_int32 num_tables = ttUSHORT(data+fontstart+4);
stbtt_uint32 tabledir = fontstart + 12;
@ -1032,7 +1032,7 @@ STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *font_collection,
STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, int fontstart)
{
stbtt_uint8 *data = (stbtt_uint8 *) data2;
stbtt_uint8 const *data = (stbtt_uint8 const *) data2;
stbtt_uint32 cmap, t;
stbtt_int32 i,numTables;
@ -1089,7 +1089,7 @@ STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data2, i
STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint)
{
stbtt_uint8 *data = info->data;
stbtt_uint8 const *data = info->data;
stbtt_uint32 index_map = info->index_map;
stbtt_uint16 format = ttUSHORT(data + index_map + 0);
@ -1257,8 +1257,8 @@ static int stbtt__close_shape(stbtt_vertex *vertices, int num_vertices, int was_
STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices)
{
stbtt_int16 numberOfContours;
stbtt_uint8 *endPtsOfContours;
stbtt_uint8 *data = info->data;
stbtt_uint8 const *endPtsOfContours;
stbtt_uint8 const *data = info->data;
stbtt_vertex *vertices=0;
int num_vertices=0;
int g = stbtt__GetGlyfOffset(info, glyph_index);
@ -1273,7 +1273,7 @@ STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, s
stbtt_uint8 flags=0,flagcount;
stbtt_int32 ins, i,j=0,m,n, next_move, was_off=0, off, start_off=0;
stbtt_int32 x,y,cx,cy,sx,sy, scx,scy;
stbtt_uint8 *points;
stbtt_uint8 const *points;
endPtsOfContours = (data + g + 10);
ins = ttUSHORT(data + g + 10 + numberOfContours * 2);
points = data + g + 10 + numberOfContours * 2 + 2 + ins;
@ -1395,7 +1395,7 @@ STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, s
} else if (numberOfContours == -1) {
// Compound shapes.
int more = 1;
stbtt_uint8 *comp = data + g + 10;
stbtt_uint8 const *comp = data + g + 10;
num_vertices = 0;
vertices = 0;
while (more) {
@ -1494,7 +1494,7 @@ STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_inde
STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2)
{
stbtt_uint8 *data = info->data + info->kern;
stbtt_uint8 const *data = info->data + info->kern;
stbtt_uint32 needle, straw;
int l, r, m;
@ -3109,7 +3109,7 @@ STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const
STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID)
{
stbtt_int32 i,count,stringOffset;
stbtt_uint8 *fc = font->data;
stbtt_uint8 const *fc = font->data;
stbtt_uint32 offset = font->fontstart;
stbtt_uint32 nm = stbtt__find_table(fc, offset, "name");
if (!nm) return NULL;
@ -3127,7 +3127,7 @@ STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *l
return NULL;
}
static int stbtt__matchpair(stbtt_uint8 *fc, stbtt_uint32 nm, stbtt_uint8 *name, stbtt_int32 nlen, stbtt_int32 target_id, stbtt_int32 next_id)
static int stbtt__matchpair(stbtt_uint8 const *fc, stbtt_uint32 nm, stbtt_uint8 const *name, stbtt_int32 nlen, stbtt_int32 target_id, stbtt_int32 next_id)
{
stbtt_int32 i;
stbtt_int32 count = ttUSHORT(fc+nm+2);
@ -3157,7 +3157,7 @@ static int stbtt__matchpair(stbtt_uint8 *fc, stbtt_uint32 nm, stbtt_uint8 *name,
return 1;
} else if (matchlen < nlen && name[matchlen] == ' ') {
++matchlen;
if (stbtt_CompareUTF8toUTF16_bigendian((char*) (name+matchlen), nlen-matchlen, (char*)(fc+stringOffset+off),slen))
if (stbtt_CompareUTF8toUTF16_bigendian((char const*) (name+matchlen), nlen-matchlen, (char const*)(fc+stringOffset+off),slen))
return 1;
}
} else {
@ -3174,9 +3174,9 @@ static int stbtt__matchpair(stbtt_uint8 *fc, stbtt_uint32 nm, stbtt_uint8 *name,
return 0;
}
static int stbtt__matches(stbtt_uint8 *fc, stbtt_uint32 offset, stbtt_uint8 *name, stbtt_int32 flags)
static int stbtt__matches(stbtt_uint8 const *fc, stbtt_uint32 offset, stbtt_uint8 const *name, stbtt_int32 flags)
{
stbtt_int32 nlen = (stbtt_int32) STBTT_strlen((char *) name);
stbtt_int32 nlen = (stbtt_int32) STBTT_strlen((char const *) name);
stbtt_uint32 nm,hd;
if (!stbtt__isfont(fc+offset)) return 0;
@ -3209,7 +3209,7 @@ STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *font_collection, const
for (i=0;;++i) {
stbtt_int32 off = stbtt_GetFontOffsetForIndex(font_collection, i);
if (off < 0) return off;
if (stbtt__matches((stbtt_uint8 *) font_collection, off, (stbtt_uint8*) name_utf8, flags))
if (stbtt__matches((stbtt_uint8 const *) font_collection, off, (stbtt_uint8 const *) name_utf8, flags))
return off;
}
}