{"id":22962323,"url":"https://github.com/zonble/humanstring","last_synced_at":"2025-08-13T06:33:48.150Z","repository":{"id":56914739,"uuid":"201169241","full_name":"zonble/HumanString","owner":"zonble","description":null,"archived":false,"fork":false,"pushed_at":"2022-01-28T17:59:40.000Z","size":178,"stargazers_count":27,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-16T07:34:22.127Z","etag":null,"topics":["strings","swift"],"latest_commit_sha":null,"homepage":"https://zonble.github.io/HumanString/index.html","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zonble.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-08T03:15:51.000Z","updated_at":"2022-03-23T22:04:12.000Z","dependencies_parsed_at":"2022-08-21T02:50:58.237Z","dependency_job_id":null,"html_url":"https://github.com/zonble/HumanString","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zonble%2FHumanString","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zonble%2FHumanString/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zonble%2FHumanString/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zonble%2FHumanString/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zonble","download_url":"https://codeload.github.com/zonble/HumanString/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229743813,"owners_count":18117460,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["strings","swift"],"created_at":"2024-12-14T19:16:33.323Z","updated_at":"2025-08-13T06:33:48.132Z","avatar_url":"https://github.com/zonble.png","language":"Swift","readme":"# HumanString\n\n[![Actions Status](https://github.com/zonble/HumanString/workflows/Build/badge.svg)](https://github.com/zonble/HumanString/actions)\n[![codecov](https://codecov.io/gh/zonble/HumanString/branch/master/graph/badge.svg)](https://codecov.io/gh/zonble/HumanString)\n\nHumanString is a package that let you use integers but not String.Index to\nspecify ranges in strings.\n\n``` swift\nlet str = \"今天天氣好清爽\"\nXCTAssertTrue(str[0] == \"今\")\nXCTAssertTrue(str[4] == \"好\")\nXCTAssertTrue(str[-1] == \"爽\")\nXCTAssertTrue(str[0..\u003c2] == \"今天\")\nXCTAssertTrue(str[0...2] == \"今天天\")\nXCTAssertTrue(str[-3 ..\u003c -1] == \"好清\")\nXCTAssertTrue(str[-3 ... -1] == \"好清爽\")\nXCTAssertTrue(str[-3 ... 0] == nil)\nXCTAssertTrue(str[-3 ..\u003c 0] == \"好清爽\")\nXCTAssertTrue(str[-3 ..\u003c 1] == nil)\nXCTAssertTrue(str[-3 ... 1] == nil)\nXCTAssertTrue(str[0...] == \"今天天氣好清爽\")\nXCTAssertTrue(str[1...] == \"天天氣好清爽\")\nXCTAssertTrue(str[(-2)...] == \"清爽\")\nXCTAssertTrue(str[(-1)...] == \"爽\")\nXCTAssertTrue(str[..\u003c3] == \"今天天\")\nXCTAssertTrue(str[...3] == \"今天天氣\")\nXCTAssertTrue(str[..\u003c(-1)] == \"今天天氣好清\")\nXCTAssertTrue(str[...(-1)] == \"今天天氣好清爽\")\n```\n\n## Installation\n\nYou can install the package using Swift package manager. Add the following lines to your `Packages.swift` file:\n\n```\ndependencies: [\n    .package(url: \"https://github.com/zonble/HumanString.git\"),\n],\n```\n\nYou can also install the library using CocoaPods, just add `pod \"HumanString\"`\nto you Podfile.\n\n## Notes\n\nSwift adopts String.Index since Swift 4. It tends to reminder you that the width\nof a string is not fixed (See[Strings in Swift 4](https://oleb.net/blog/2017/11/swift-4-strings/)).\nHowever, it is somehow painful. For example, if you want to extract a prefix\nfrom \"Hello World\", it could be:\n\n``` swift\nlet str = \"Hello World\"\nlet subString = s[...str.index(str.startIndex, offsetBy: 5)]\n```\n\nBut wait, somehow you are still using integers, right? The code above could be\nwritten as:\n\n``` swift\nlet subString = s[str.index(str.startIndex, offsetBy: 0)...str.index(str.startIndex, offsetBy: 5)]\n```\n\nI know the Swift team does not like what I am doing here, but somehow I still\nwant to make my life easier.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzonble%2Fhumanstring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzonble%2Fhumanstring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzonble%2Fhumanstring/lists"}