mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 567283 patch 1 - Convert if enclosing most of function into early return. r=xidorn
This conversion just reindents most of the function, but it then avoids having indentation changes in patch 2. MozReview-Commit-ID: A5unK4grJ47
This commit is contained in:
parent
8fd021fbd4
commit
bf5666a4c5
@ -80,42 +80,42 @@ bool NS_HexToRGB(const nsAString& aColorSpec, nscolor* aResult)
|
||||
const char16_t* buffer = aColorSpec.BeginReading();
|
||||
|
||||
int nameLen = aColorSpec.Length();
|
||||
if ((nameLen == 3) || (nameLen == 6)) {
|
||||
// Make sure the digits are legal
|
||||
for (int i = 0; i < nameLen; i++) {
|
||||
char16_t ch = buffer[i];
|
||||
if (((ch >= '0') && (ch <= '9')) ||
|
||||
((ch >= 'a') && (ch <= 'f')) ||
|
||||
((ch >= 'A') && (ch <= 'F'))) {
|
||||
// Legal character
|
||||
continue;
|
||||
}
|
||||
// Whoops. Illegal character.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert the ascii to binary
|
||||
int dpc = ((3 == nameLen) ? 1 : 2);
|
||||
// Translate components from hex to binary
|
||||
int r = ComponentValue(buffer, nameLen, 0, dpc);
|
||||
int g = ComponentValue(buffer, nameLen, 1, dpc);
|
||||
int b = ComponentValue(buffer, nameLen, 2, dpc);
|
||||
if (dpc == 1) {
|
||||
// Scale single digit component to an 8 bit value. Replicate the
|
||||
// single digit to compute the new value.
|
||||
r = (r << 4) | r;
|
||||
g = (g << 4) | g;
|
||||
b = (b << 4) | b;
|
||||
}
|
||||
NS_ASSERTION((r >= 0) && (r <= 255), "bad r");
|
||||
NS_ASSERTION((g >= 0) && (g <= 255), "bad g");
|
||||
NS_ASSERTION((b >= 0) && (b <= 255), "bad b");
|
||||
*aResult = NS_RGB(r, g, b);
|
||||
return true;
|
||||
if (nameLen != 3 && nameLen != 6) {
|
||||
// Improperly formatted color value
|
||||
return false;
|
||||
}
|
||||
|
||||
// Improperly formatted color value
|
||||
return false;
|
||||
// Make sure the digits are legal
|
||||
for (int i = 0; i < nameLen; i++) {
|
||||
char16_t ch = buffer[i];
|
||||
if (((ch >= '0') && (ch <= '9')) ||
|
||||
((ch >= 'a') && (ch <= 'f')) ||
|
||||
((ch >= 'A') && (ch <= 'F'))) {
|
||||
// Legal character
|
||||
continue;
|
||||
}
|
||||
// Whoops. Illegal character.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert the ascii to binary
|
||||
int dpc = ((3 == nameLen) ? 1 : 2);
|
||||
// Translate components from hex to binary
|
||||
int r = ComponentValue(buffer, nameLen, 0, dpc);
|
||||
int g = ComponentValue(buffer, nameLen, 1, dpc);
|
||||
int b = ComponentValue(buffer, nameLen, 2, dpc);
|
||||
if (dpc == 1) {
|
||||
// Scale single digit component to an 8 bit value. Replicate the
|
||||
// single digit to compute the new value.
|
||||
r = (r << 4) | r;
|
||||
g = (g << 4) | g;
|
||||
b = (b << 4) | b;
|
||||
}
|
||||
NS_ASSERTION((r >= 0) && (r <= 255), "bad r");
|
||||
NS_ASSERTION((g >= 0) && (g <= 255), "bad g");
|
||||
NS_ASSERTION((b >= 0) && (b <= 255), "bad b");
|
||||
*aResult = NS_RGB(r, g, b);
|
||||
return true;
|
||||
}
|
||||
|
||||
// This implements part of the algorithm for legacy behavior described in
|
||||
|
Loading…
Reference in New Issue
Block a user