Skip to content

Commit

Permalink
Merge pull request #147 from Flipez/fix-string-count-find-args
Browse files Browse the repository at this point in the history
[object/string] Fix `.find()` and `.count()`  argument validation to only accept STRING
  • Loading branch information
Flipez authored Nov 1, 2022
2 parents a027137 + 5eb1a2c commit db13aa7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
8 changes: 3 additions & 5 deletions docs/docs/literals/string.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ puts(s)

## Literal Specific Methods

### count(STRING|INTEGER)
### count(STRING)
> Returns `INTEGER`
Counts how often a given string or integer occurs in the string. Converts given integers to strings automatically.
Counts how often a given substring occurs in the string.


```js
Expand All @@ -57,8 +57,6 @@ Counts how often a given string or integer occurs in the string. Converts given
=> 0
🚀 > "test1".count("1")
=> 1
🚀 > "test1".count(1)
=> 1
```


Expand Down Expand Up @@ -91,7 +89,7 @@ Replaces all upcase characters with lowercase counterparts.
```


### find(STRING|INTEGER)
### find(STRING)
> Returns `INTEGER`
Returns the character index of a given string if found. Otherwise returns `-1`
Expand Down
10 changes: 4 additions & 6 deletions object/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ func init() {
objectMethods[STRING_OBJ] = map[string]ObjectMethod{
"count": ObjectMethod{
Layout: MethodLayout{
Description: "Counts how often a given string or integer occurs in the string. Converts given integers to strings automatically.",
Description: "Counts how often a given substring occurs in the string.",
Example: `🚀 > "test".count("t")
=> 2
🚀 > "test".count("f")
=> 0
🚀 > "test1".count("1")
=> 1
🚀 > "test1".count(1)
=> 1`,
ArgPattern: Args(
Arg(STRING_OBJ, INTEGER_OBJ), // first argument can be string or int
Arg(STRING_OBJ),
),
ReturnPattern: Args(
Arg(INTEGER_OBJ),
Expand All @@ -51,7 +49,7 @@ func init() {
🚀 > "test".find("f")
=> -1`,
ArgPattern: Args(
Arg(STRING_OBJ, INTEGER_OBJ), // first argument can be string or int
Arg(STRING_OBJ),
),
ReturnPattern: Args(
Arg(INTEGER_OBJ),
Expand All @@ -73,7 +71,7 @@ func init() {
🚀 » "test%s".format("test")
» "testtest"`,
ArgPattern: Args(
OverloadArg(STRING_OBJ, INTEGER_OBJ, FLOAT_OBJ, BOOLEAN_OBJ), // first argument can be string or int
OverloadArg(STRING_OBJ, INTEGER_OBJ, FLOAT_OBJ, BOOLEAN_OBJ),
),
ReturnPattern: Args(
Arg(STRING_OBJ),
Expand Down

2 comments on commit db13aa7

@vercel
Copy link

@vercel vercel bot commented on db13aa7 Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on db13aa7 Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.