Created
January 30, 2023 04:40
-
-
Save eyasuyuki/bcc97f3a712dca926676701b9d65fe17 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(use srfi-13) | |
(use gauche.test) | |
(define (starts-with? str prefix) | |
(let ((str-len (string-length str)) | |
(prefix-len (string-length prefix))) | |
(if (> str-len prefix-len) | |
(string=? (substring str 0 prefix-len) prefix) | |
#f))) | |
(define (remove-bom path) | |
(let* ((bom (string #xEF #xBB #xBF)) | |
(content (slurp path))) | |
(if (starts-with? content bom) | |
(let ((new-content (substring content (string-length bom)))) | |
(spit path new-content))))) | |
(define (walk path) | |
(if (file-directory? path) | |
(do-directory path walk) | |
(if (string-suffix? ".java" path) | |
(remove-bom path)))) | |
(define (test-remove-bom path) | |
(let ((file (open path "wb"))) | |
(write-string (string #xEF #xBB #xBF) file) | |
(write-string "hello" file) | |
(close file)) | |
(remove-bom path) | |
(let ((content (slurp path))) | |
(assert-string= content "hello"))) | |
(define-test-group remove-bom | |
(test-remove-bom "bom.txt")) | |
(run-tests) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment