{"id":39874428,"url":"https://github.com/liyu1981/jstring.zig","last_synced_at":"2026-01-18T14:22:17.886Z","repository":{"id":218849251,"uuid":"745447090","full_name":"liyu1981/jstring.zig","owner":"liyu1981","description":"a reusable string lib for myself with all familiar methods methods can find in javascript string","archived":false,"fork":false,"pushed_at":"2024-04-26T01:49:49.000Z","size":6092,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-26T15:27:57.068Z","etag":null,"topics":["jstring","zig","zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/liyu1981.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-01-19T10:58:50.000Z","updated_at":"2024-04-26T01:49:52.000Z","dependencies_parsed_at":"2024-01-24T06:26:33.971Z","dependency_job_id":"6ad3995d-7820-4b11-a67a-b054131dc3ac","html_url":"https://github.com/liyu1981/jstring.zig","commit_stats":null,"previous_names":["liyu1981/jstring.zig"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/liyu1981/jstring.zig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyu1981%2Fjstring.zig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyu1981%2Fjstring.zig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyu1981%2Fjstring.zig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyu1981%2Fjstring.zig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liyu1981","download_url":"https://codeload.github.com/liyu1981/jstring.zig/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liyu1981%2Fjstring.zig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28537528,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T13:04:05.990Z","status":"ssl_error","status_checked_at":"2026-01-18T13:01:44.092Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["jstring","zig","zig-package"],"created_at":"2026-01-18T14:22:17.793Z","updated_at":"2026-01-18T14:22:17.880Z","avatar_url":"https://github.com/liyu1981.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `jstring.zig`\n\n## Target: create a reusable string lib for myself with all familiar methods methods can find in javascript string.\n\n## Reason:\n\n1.  string is important we all know, so a good string lib will be very useful.\n2.  javascript string is (in my opinion) the most battle tested string library out there, strike a good balance\n    between features and complexity.\n\nThe javascript string specs and methods this file use as reference can be found at\nhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String\n\nAll methods except those marked as deprecated (such as anchor, big, blink etc) are implemented, in zig way.\n\n# integration with PCRE2 regex\n\nOne highlight of `jstring.zig` is that it integrates with [PCRE2](https://www.pcre.org/) to provide `match`, `match_all` and more just like the familar feeling of javascript string.\n\nhere are some examples of how regex can be used\n\n```zig\nvar str1 = try JStringUnmanaged.newFromSlice(arena.allocator(), \"hello,hello,world\");\nvar results = try str1.splitByRegex(arena.allocator(), \"l+\", 0, 0);\ntry testing.expectEqual(results.len, 1);\ntry testing.expect(results[0].eqlSlice(\"hello,hello,world\"));\nresults = try str1.splitByRegex(arena.allocator(), \"l+\", 0, -1);\ntry testing.expectEqual(results.len, 4);\ntry testing.expect(results[0].eqlSlice(\"he\"));\ntry testing.expect(results[1].eqlSlice(\"o,he\"));\ntry testing.expect(results[2].eqlSlice(\"o,wor\"));\ntry testing.expect(results[3].eqlSlice(\"d\"));\n```\n\n# usage\n\n```bash\nzig fetch --save https://github.com/liyu1981/jstring.zig/archive/refs/tags/0.1.1.tar.gz\n```\n\ncheck `example` folder for a sample project\n\n```zig\nconst std = @import(\"std\");\nconst jstring = @import(\"jstring\");\n\npub fn main() !u8 {\n    var your_name = brk: {\n        var jstr = try jstring.JString.newFromSlice(std.heap.page_allocator, \"name is: zig\");\n        defer jstr.deinit();\n        const m = try jstr.match(\"name is: (?\u003cname\u003e.+)\", 0, true, 0, 0);\n        if (m.matchSucceed()) {\n            const r = m.getGroupResultByName(\"name\");\n            break :brk try jstr.slice(\n                @as(isize, @intCast(r.?.start)),\n                @as(isize, @intCast(r.?.start + r.?.len)),\n            );\n        }\n        unreachable;\n    };\n    defer your_name.deinit();\n\n    try std.io.getStdOut().writer().print(\"\\nhello, {s}\\n\", .{your_name});\n    return 0;\n}\n```\n\nin order to run this example from the `git clone` repo, you will need\n\n```bash\ncd \u003cjstirng_repo\u003e/examples\nzig fetch --save ../ # to update your local zig cache about jstring\nzig build run\n```\n\n# `build.zig`\n\nwhen use `jstring.zig` in your project, as it integrates with `PCRE2`, will need to link your project to `libpcre-8`. `jstring.zig` provide a build time function to easy this process.\n\n```zig\n// in your build.zig\nconst jstring_build = @import(\"jstring\");\n...\nconst jstring_dep = b.dependency(\"jstring\", .{});\nexe.addModule(\"jstring\", jstring_dep.module(\"jstring\"));\njstring_build.linkPCRE(exe, jstring_dep);\n```\n\nagain, check `example` folder for the usage\n\n# performance\n\n`jstring.zig` is built with performance in mind. Though `benchmark` is still in developing, but the initial result of allocate/free 1M random size of strings shows a _~70%_ advantage comparing to c++/20's `std::string`.\n\n```bash\nbenchmark % ./zig-out/bin/benchmark\n|zig create/release: | [ooooo] | avg=    16464000ns | min=    14400000ns | max=    20975000ns |\n|cpp create/release: | [ooooo] | avg=    56735400ns | min=    56137000ns | max=    57090000ns |\n```\n\n(`jstring.zig` is built with `-Doptimize=ReleaseFast`, and `cpp` is built with `-std=c++20 -O2`)\n\ncheck current benchmark method [here](https://github.com/liyu1981/jstring.zig/blob/main/tools/benchmark/main.zig)\n\n# docs\n\ncheck the auto generated zig docs [here](https://liyu1981.github.io/jstring.zig)\n\n# tests\n\n`jstring` is rigorously tested.\n\n```bash\n./script/pcre_test.sh src/jstring.zig\n```\n\nto run all tests.\n\nor check kcov report [here](https://liyu1981.github.io/jstring.zig/cov/index.html): the current level is 100%.\n\n# license\n\nMIT License :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliyu1981%2Fjstring.zig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliyu1981%2Fjstring.zig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliyu1981%2Fjstring.zig/lists"}