-
Notifications
You must be signed in to change notification settings - Fork 911
[Bugfix] 修复 #6348 资源包管理处理非UTF-8编码的options.txt文件时出错
#6351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
79de248
9420f70
34d122b
c1c1672
79dc5c9
7672227
4d7c031
a28e79d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,12 +17,16 @@ | |
| */ | ||
| package org.jackhuang.hmcl.util; | ||
|
|
||
| import org.glavo.chardet.UniversalDetector; | ||
| import org.jackhuang.hmcl.util.gson.JsonUtils; | ||
| import org.jackhuang.hmcl.util.platform.OperatingSystem; | ||
| import org.jetbrains.annotations.Contract; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| import java.io.PrintWriter; | ||
| import java.io.StringWriter; | ||
| import java.nio.charset.Charset; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.*; | ||
| import java.util.function.Predicate; | ||
| import java.util.regex.Matcher; | ||
|
|
@@ -630,6 +634,17 @@ public static List<String> deserializeStringList(String json) { | |
| return JsonUtils.fromNonNullJson(json, JsonUtils.listTypeOf(String.class)); | ||
| } | ||
|
|
||
| public static Charset maybeDetectTextEncoding(byte[] data) { | ||
|
ToobLac marked this conversation as resolved.
Outdated
|
||
| var detector = new UniversalDetector(); | ||
| detector.handleData(data); | ||
| detector.dataEnd(); | ||
| var detected = detector.getDetectedCharset(); | ||
| if (detected == null || !detected.isSupported()) return OperatingSystem.NATIVE_CHARSET; | ||
| var charset = detected.getCharset(); | ||
| if (charset == StandardCharsets.UTF_8 || charset == StandardCharsets.US_ASCII) return StandardCharsets.UTF_8; | ||
| return OperatingSystem.NATIVE_CHARSET; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 无需担心,这种情况MC也读取不了,就不管了(
ToobLac marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| public static class LevCalculator { | ||
| private int[][] lev; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.