mirror of
https://github.com/deavmi/birchwood
synced 2024-09-20 14:23:38 +02:00
Exceptions
- Added new `ErrorType` enum member `INVALID_FORMATTING` Formatting - All formatting functions will now throw a `BirchwoodException` instead of a `StringException` on invalid formatting parameters
This commit is contained in:
parent
1ca052978b
commit
51a04659c5
@ -56,7 +56,13 @@ public enum ErrorType
|
|||||||
* If the final encoded IRC message
|
* If the final encoded IRC message
|
||||||
* is too long to send to the server
|
* is too long to send to the server
|
||||||
*/
|
*/
|
||||||
COMMAND_TOO_LONG
|
COMMAND_TOO_LONG,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If invalid parameters are passed
|
||||||
|
* to any of the text formatting functions
|
||||||
|
*/
|
||||||
|
INVALID_FORMATTING
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
module birchwood.protocol.formatting;
|
module birchwood.protocol.formatting;
|
||||||
|
|
||||||
// FIXME: Remove below import and start using BirchwoodException
|
import birchwood.client.exceptions;
|
||||||
import std.string;
|
|
||||||
|
|
||||||
// Reset character; resets all formatting
|
// Reset character; resets all formatting
|
||||||
enum reset_code = '\x0F';
|
enum reset_code = '\x0F';
|
||||||
@ -52,7 +51,7 @@ char generate_color_control_char(string color) {
|
|||||||
} else if (color.length == 2) {
|
} else if (color.length == 2) {
|
||||||
return ascii_color_code;
|
return ascii_color_code;
|
||||||
} else {
|
} else {
|
||||||
throw new StringException("Invalid color code (must be either two ASCII digits or a hexadecimal code of the form RRGGBB)");
|
throw new BirchwoodException(ErrorType.INVALID_FORMATTING, "Invalid color code (must be either two ASCII digits or a hexadecimal code of the form RRGGBB)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +63,7 @@ string set_foreground(string color) {
|
|||||||
} else if (color.length == 2) {
|
} else if (color.length == 2) {
|
||||||
control_char[0] = ascii_color_code;
|
control_char[0] = ascii_color_code;
|
||||||
} else {
|
} else {
|
||||||
throw new StringException("Invalid color code (must be either two ASCII digits or a hexadecimal code of the form RRGGBB)");
|
throw new BirchwoodException(ErrorType.INVALID_FORMATTING, "Invalid color code (must be either two ASCII digits or a hexadecimal code of the form RRGGBB)");
|
||||||
}
|
}
|
||||||
return control_char.idup ~ color;
|
return control_char.idup ~ color;
|
||||||
}
|
}
|
||||||
@ -73,14 +72,14 @@ string set_foreground(string color) {
|
|||||||
string set_foreground_background(string fg, string bg) {
|
string set_foreground_background(string fg, string bg) {
|
||||||
char[1] control_char;
|
char[1] control_char;
|
||||||
if (fg.length != bg.length) {
|
if (fg.length != bg.length) {
|
||||||
throw new StringException("Invalid color code (cannot mix hex and ASCII)");
|
throw new BirchwoodException(ErrorType.INVALID_FORMATTING, "Invalid color code (cannot mix hex and ASCII)");
|
||||||
}
|
}
|
||||||
if (fg.length == 6) {
|
if (fg.length == 6) {
|
||||||
control_char[0] = hex_color_code;
|
control_char[0] = hex_color_code;
|
||||||
} else if (fg.length == 2) {
|
} else if (fg.length == 2) {
|
||||||
control_char[0] = ascii_color_code;
|
control_char[0] = ascii_color_code;
|
||||||
} else {
|
} else {
|
||||||
throw new StringException("Invalid color code (must be either two ASCII digits or a hexadecimal code of the form RRGGBB)");
|
throw new BirchwoodException(ErrorType.INVALID_FORMATTING, "Invalid color code (must be either two ASCII digits or a hexadecimal code of the form RRGGBB)");
|
||||||
}
|
}
|
||||||
return control_char.idup ~ fg ~ "," ~ bg;
|
return control_char.idup ~ fg ~ "," ~ bg;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user