Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,4 @@ The reader can cite our work with the following BibTeX entry:
year = {2024},
url = {https://github.com/LiiiLabs/goldfish/releases/download/v17.10.9/Goldfish.pdf}
}
```
```
2 changes: 1 addition & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,4 @@ based on S7 Scheme 11.5 (22-Sep-2025)
year = {2024},
url = {https://gitee.com/LiiiLabs/goldfish/releases/download/v17.10.9/Goldfish.pdf}
}
```
```
3 changes: 3 additions & 0 deletions devel/210_31.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# [210_31]

## 2026/03/25 新增 string-contains?
8 changes: 4 additions & 4 deletions goldfish/liii/rich-string.scm
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,18 @@

(define (%contains elem)
(cond ((rich-string :is-type-of elem)
(string-contains data (elem :get)))
(string-contains? data (elem :get)))

((string? elem)
(string-contains data elem)
(string-contains? data elem)
) ;

((rich-char :is-type-of elem)
(string-contains data (elem :make-string))
(string-contains? data (elem :make-string))
) ;

((char? elem)
(string-contains data (string elem))
(string-contains? data (string elem))
) ;

(else (type-error "elem must be char or string"))
Expand Down
9 changes: 7 additions & 2 deletions goldfish/liii/string.scm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
string-reverse
string-tokenize
; Liii extras
string-starts? string-ends?
string-starts? string-contains? string-ends?
string-remove-prefix string-remove-suffix
) ;export
(import (srfi srfi-13)
Expand All @@ -49,6 +49,12 @@
) ;if
) ;define

(define string-contains?
(typed-lambda ((str string?) (sub-str string?))
(string-contains str sub-str)
) ;typed-lambda
) ;define

(define (string-ends? str suffix)
(if (and (string? str) (string? suffix))
(string-suffix? suffix str)
Expand Down Expand Up @@ -76,4 +82,3 @@

) ;begin
) ;define-library

42 changes: 42 additions & 0 deletions tests/goldfish/liii/string-test.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,48 @@ out-of-range 当start/end超出字符串索引范围时
(check-true (string-contains "0123456789" "34"))
(check-false (string-contains "0123456789" "24"))

#|
string-contains?
检查字符串是否包含指定子串。

语法
----
(string-contains? str sub-str)

参数
----
str : string?
要检查的源字符串。

sub-str : string?
要查找的子串。

返回值
----
boolean
如果str包含sub-str返回#t,否则返回#f。

注意
----
`string-contains?` 是 `string-contains` 的谓词风格别名,更符合布尔判定 API 的命名直觉。
空字符串作为sub-str时总是返回#t。

错误处理
----
type-error 当参数不是字符串类型时。
|#

(check-true (string-contains? "0123456789" "3"))
(check-true (string-contains? "0123456789" "34"))
(check-false (string-contains? "0123456789" "24"))
(check-true (string-contains? "" ""))
(check-true (string-contains? "hello" ""))
(check-false (string-contains? "" "a"))
(check-true (string-contains? "中文测试" "文测"))
(check-false (string-contains? "Hello" "hello"))
(check-catch 'type-error (string-contains? 123 "1"))
(check-catch 'type-error (string-contains? "123" 1))

#|
string-count
统计字符串中满足指定条件的字符数量。
Expand Down
Loading