Skip to content

Commit

Permalink
adjusted string manipulation
Browse files Browse the repository at this point in the history
Made some bool checks explicit, removed deletion of whitespace before the speaker text, and updated the test case.
  • Loading branch information
Pokeizel committed Apr 21, 2022
1 parent bafb745 commit 0cc5183
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions datafiles/testcase_parsers.yarn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ __PrivCrochet_position: -80,0
__PrivCrochet_tags:
title: Start
---
Chatterbox[0]: I have been parsed. My identity, my values, my thoughts... they've all been misinterpreted.
Chatterbox[1]: Nobody can truly understand how this feels.
Chatterbox [2] : No one realizes how much space there really is between you and me.
Chatterbox: This is some text with a name.
Chatterbox[1]: This is more text with a name and metadata.
Chatterbox [2] : This is even more text with a name, metadata, and invisible whitespace!
===
2 changes: 1 addition & 1 deletion options/operagx/options_operagx.yy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions scripts/ChatterboxGetSpeaker/ChatterboxGetSpeaker.gml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function ChatterboxGetSpeaker(_chatterbox, _index)
if (_str != undefined)
{
var _colon = string_pos(":", _str);
if (!_colon)
if (_colon == 0)
{
show_debug_message("Chatterbox: No speaker found.") return "";
}
Expand All @@ -18,7 +18,7 @@ function ChatterboxGetSpeaker(_chatterbox, _index)
var _c2 = CHATTERBOX_SPEAKERDATA_TAG_CLOSE;
var _char_l = string_pos(_c1, _str);
var _char_r = string_pos(_c2, _str);
if (_char_l and _char_r < _colon) //If there are tags before the colon
if (_char_l > 0 and _char_r < _colon) //If there are tags before the colon
{
_name = string_delete(_name, _char_l, _colon-_char_l+1); //Remove everything between the L bracket and the colon
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function ChatterboxGetSpeakerData(_chatterbox, _index, _default = undefined)
var _c2 = CHATTERBOX_SPEAKERDATA_TAG_CLOSE;
var _char_l = string_pos(_c1, _str);
var _char_r = string_pos(_c2, _str);
if (_char_l and _char_r < _colon)
if (_char_l > 0 and _char_r < _colon)
{
var _data = string_copy(_str, _char_l+1, _char_r-_char_l-1);
return _data;
Expand Down
12 changes: 6 additions & 6 deletions scripts/ChatterboxGetSpeech/ChatterboxGetSpeech.gml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ function ChatterboxGetSpeech(_chatterbox, _index)
{
var _colon = string_pos(":", _str);
var _space = 0;
if (_colon != 0) //If there *is* a colon
if (_colon > 0) //If there is a colon
{
_speech = string_delete(_str, 1, _colon); //Remove the colon and all behind it,
}
if (string_pos(" ", _speech) == 1) //If there's as the first character
{
for (var i = 0; string_char_at(_speech, i) == " "; ++i) {
_space++;
if (string_pos(" ", _speech) == 1) //If there is still whitespace remaining, remove it
{
for (var i = 0; string_char_at(_speech, i) == " "; ++i) {
_space++;
}
}
}
_str = string_copy(_speech, _space, string_length(_speech));
Expand Down

0 comments on commit 0cc5183

Please sign in to comment.