-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from mrichards42/string-char-args
Allow passing char to some joker.string functions
- Loading branch information
Showing
4 changed files
with
56 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func AssertStringable(obj Object, msg string) String { | ||
switch c := obj.(type) { | ||
case String: | ||
return c | ||
case Char: | ||
return String{S: string(c.Ch)} | ||
default: | ||
if msg == "" { | ||
msg = fmt.Sprintf("Expected %s, got %s", "Stringable", obj.GetType().ToString(false)) | ||
} | ||
panic(RT.NewError(msg)) | ||
} | ||
} | ||
|
||
func EnsureStringable(args []Object, index int) String { | ||
switch c := args[index].(type) { | ||
case String: | ||
return c | ||
case Char: | ||
return String{S: string(c.Ch)} | ||
default: | ||
panic(RT.NewArgTypeError(index, c, "Stringable")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters