{"id":32149456,"url":"https://github.com/perfectsiderepos/perfect-iconv","last_synced_at":"2025-10-21T09:58:00.564Z","repository":{"id":16287230,"uuid":"79669748","full_name":"PerfectSideRepos/Perfect-ICONV","owner":"PerfectSideRepos","description":"A Swif Class Wrapper for ICONV, Inspired by Yasuhiro Hatta","archived":false,"fork":false,"pushed_at":"2022-05-19T20:28:21.000Z","size":18,"stargazers_count":4,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-21T09:57:37.556Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PerfectSideRepos.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":"2017-01-21T20:06:44.000Z","updated_at":"2025-09-10T19:00:22.000Z","dependencies_parsed_at":"2022-11-28T10:39:18.244Z","dependency_job_id":null,"html_url":"https://github.com/PerfectSideRepos/Perfect-ICONV","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/PerfectSideRepos/Perfect-ICONV","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectSideRepos%2FPerfect-ICONV","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectSideRepos%2FPerfect-ICONV/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectSideRepos%2FPerfect-ICONV/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectSideRepos%2FPerfect-ICONV/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PerfectSideRepos","download_url":"https://codeload.github.com/PerfectSideRepos/Perfect-ICONV/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectSideRepos%2FPerfect-ICONV/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280240316,"owners_count":26296527,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-10-21T09:57:59.671Z","updated_at":"2025-10-21T09:58:00.559Z","avatar_url":"https://github.com/PerfectSideRepos.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Perfect ICONV [简体中文](README.zh_CN.md)\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"http://perfect.org/get-involved.html\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://perfect.org/assets/github/perfect_github_2_0_0.jpg\" alt=\"Get Involed with Perfect!\" width=\"854\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/PerfectlySoft/Perfect\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_1_Star.jpg\" alt=\"Star Perfect On Github\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"http://stackoverflow.com/questions/tagged/perfect\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/perfect_gh_button_2_SO.jpg\" alt=\"Stack Overflow\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"https://twitter.com/perfectlysoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_3_twit.jpg\" alt=\"Follow Perfect on Twitter\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"http://perfect.ly\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_4_slack.jpg\" alt=\"Join the Perfect Slack\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Swift-4.1-orange.svg?style=flat\" alt=\"Swift 4.1\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Platforms-OS%20X%20%7C%20Linux%20-lightgray.svg?style=flat\" alt=\"Platforms OS X | Linux\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://perfect.org/licensing.html\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/License-Apache-lightgrey.svg?style=flat\" alt=\"License Apache\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://twitter.com/PerfectlySoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Twitter-@PerfectlySoft-blue.svg?style=flat\" alt=\"PerfectlySoft Twitter\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://perfect.ly\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://perfect.ly/badge.svg\" alt=\"Slack Status\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\nSwift Class Wrapper for ICONV, inspired by Yasuhiro Hatta's Iconv Project. See [https://github.com/yaslab/Iconv](https://github.com/yaslab/Iconv) for details.\n\nThis package builds with Swift Package Manager and is part of the [Perfect](https://github.com/PerfectlySoft/Perfect) project.\n\n## Demo\n\n``` swift\nimport PerfectICONV\n\ndo {\n  let i = try Iconv()\n  let bytes:[UInt8] =  [0xd6, 0xd0, 0xb9, 0xfa, 0x0a]\n  guard let cn = i.utf8(buf: bytes) else {\n    XCTFail(\"fault\")\n    return\n  }//end guard\n  print(cn)\n  XCTAssertTrue(cn.hasPrefix(\"中国\"))\n}catch(let err) {\n  XCTFail(\"ERROR: \\(err)\")\n}\n```\n\n## Quick Start\n\n### Swift Package Manager\n\nAdd a dependency to Package.swift:\n\n``` swift\n.Package(url: \"https://github.com/PerfectSideRepos/Perfect-ICONV.git\", \nmajorVersion:3)\n```\n\n### Header Declaration\n\nImport iconv lib to your source code:\n\n``` swift\nimport PerfectICONV\n```\n\n### Initialization\n\nSet the code pages before transforming encoding from one to another:\n\n``` swift\ndo {\n  let iconv = try Iconv(from: .GB2312, to: .UTF_8)\n}catch(let err) {\n  /// something goes wrong here, e.g., invalid code page, etc.\n}\n```\n*NOTE*: Code Page constants could be found on source code of this project with keyword of `enum`:\n``` swift\n  public enum CodePage: String {\n    case US = \"US\"\n    case US_ASCII = \"US-ASCII\"\n    case CSASCII = \"CSASCII\"\n    case UTF_8 = \"UTF-8\"\n    case UTF8 = \"UTF8\"\n    ...\n  }\n```\n### Conversions\n\nPerfectICONV has a few express ways of encoding conversions:\n\n- `iconv.utf8(bytes: [Int8])` or `iconv.utf8(bytes: [UInt8])`: directly convert a signed or unsigned byte buffer from the source code page to utf-8\n\n``` swift\nlet bytes:[UInt8] =  [0xd6, 0xd0, 0xb9, 0xfa, 0x0a]\nguard let china = iconv.utf8(buf: bytes) else {\n  /// something wrong\n}//end guard\n// if ok, it will print \"中国\"\nprint(china)\n```\n\n- `iconv.convert(buf: [Int8]) -\u003e [Int8]` or `iconv.convert(buf: [UInt8]) -\u003e [UInt8]`: convert codepages from one byte buffer to another\n\n``` swift\nlet bytes:[UInt8] =  [0xd6, 0xd0, 0xb9, 0xfa, 0x0a]\nlet chinaBytes = iconv.convert(buf: bytes)\n// if nothing wrong, the chinaBytes is now an array of UInt8 which contains the expected encoding.\n```\n\n- `iconv.convert(buf: UnsafePointer\u003cInt8\u003e, length: Int) -\u003e (UnsafeMutablePointer\u003cInt8\u003e?, Int)`: similar to Mr. Hatta's api design, convert a source encoding from a pointer with length to the objective tuple.\n ⚠️*NOTE*⚠️ YOU MUST MANUALLY DEALLOCATE THE OUTCOME POINTER.\n\n\n## Further Information\nFor more information on the Perfect project, please visit [perfect.org](http://perfect.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperfectsiderepos%2Fperfect-iconv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperfectsiderepos%2Fperfect-iconv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperfectsiderepos%2Fperfect-iconv/lists"}