virtual video::SColor getItemstackColor(const ItemStack &stack, Client *client) const { // Look for direct color definition const std::string &colorstring = stack.metadata.getString("color", 0); video::SColor directcolor; if (!colorstring.empty() && parseColorString(colorstring, directcolor, true)) return directcolor; // See if there is a palette Palette *palette = getPalette(stack.name, client); const std::string &index = stack.metadata.getString("palette_index", 0); if (palette && !index.empty()) return (*palette)[mystoi(index, 0, 255)]; // Fallback color return get(stack.name).color; }
void TestUtilities::testStrToIntConversion() { UASSERT(mystoi("123", 0, 1000) == 123); UASSERT(mystoi("123", 0, 10) == 10); }
int lex(void) { int sym; colno += toklen; char *p; char errflag = 0; do { if (errflag) { skip_line(); errflag = 0; } for (;;) { p = bufp; // skip whitespace... including comments for (;;) { while (isspace(*p)) { if (*p == '\n') { lineno++; colno = 0; } p++; colno++; } if (p[0] != '/' || p[1] != '/') break; bufp = p; skip_line(); p = bufp; } bufp = p; if ((p-buf) + MAX_TOKEN_LEN < BUFFER_SIZE || eof) break; fillbuf(); } tokstart = p; if (isalpha(*p) || *p < 0) { char *q = p+1; while (isalnum(*q) || *q < 0) q++; char saved = *q; *q = 0; struct keyword_sym *ks = gperf_keyword_sym(p, q-p); if (ks) { sym = ks->sym; } else { sym = IDENT; } *q = saved; p = q; } else if (isdigit(*p)) { char *q = p+1; while (isdigit(*q)) q++; sym = INT; p = q; } else { sym = *(unsigned char *)p; if (sym) { switch (*p++) { char *q; case ':': if (*p == '=') { p++; sym = BECOMES; } break; case '<': if (*p == '=') { p++; sym = LE; } else if (*p == '>') { p++; sym = NE; } break; case '>': if (*p == '=') { p++; sym = GE; } break; case '\'': case '"': q = p; svstrlen = 0; while (*q >= ' ' && *q != *tokstart) svstr[svstrlen++] = *q++; if (*q == *tokstart) { p = q+1; sym = *q == '"' ? STRING : CHAR; svstr[svstrlen] = 0; } else { errflag = 1; error("unmatched %c", *tokstart); } } } } } while (errflag); toklen = p-tokstart; switch (sym) { case INT: tokval.i = myatoi(tokstart, toklen); break; case IDENT: memcpy(svstr, tokstart, toklen); svstr[toklen] = 0; /* fallthrough */ case STRING: tokval.s = svstr; break; case CHAR: tokval.i = mystoi(svstr, svstrlen); } bufp = p; return sym; }