mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-24 18:13:15 -05:00
Be more robust against invalid or left out colour codes after & character. (Partially addresses #27)
This commit is contained in:
parent
103b9b5f33
commit
a9756fcb64
1 changed files with 10 additions and 2 deletions
|
@ -153,7 +153,7 @@ namespace ClassicalSharp {
|
|||
|
||||
static List<DrawTextArgs> parts = new List<DrawTextArgs>( 64 );
|
||||
public static List<DrawTextArgs> SplitText( IGraphicsApi graphics, string value, bool shadow ) {
|
||||
int code = 15;
|
||||
int code = 0xF;
|
||||
parts.Clear();
|
||||
for( int i = 0; i < value.Length; i++ ) {
|
||||
int nextAnd = value.IndexOf( '&', i );
|
||||
|
@ -164,7 +164,15 @@ namespace ClassicalSharp {
|
|||
parts.Add( new DrawTextArgs( graphics, part, colours[code], shadow ) );
|
||||
}
|
||||
i += partLength + 1;
|
||||
code = nextAnd == -1 ? 0 : Utils.ParseHex( value[nextAnd + 1] );
|
||||
|
||||
if( nextAnd >= 0 && nextAnd + 1 < value.Length ) {
|
||||
try {
|
||||
code = Utils.ParseHex( value[nextAnd + 1] );
|
||||
} catch( FormatException ) {
|
||||
code = 0xF;
|
||||
i--; // include the character that isn't a colour code.
|
||||
}
|
||||
}
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue