mirror of
https://github.com/VGEAREN/Stockbar.git
synced 2026-10-07 00:53:59 +08:00
- A-shares, HK, and US stock real-time quotes (Sina / Tencent) - Intraday minute charts (Tencent / Yahoo Finance) - US extended-hours session indicator with price and change% - Portfolio P&L tracking (cost price × shares) - Sort by change%, color themes, launch at login - File-based persistence with 10-snapshot rolling backup - Universal binary (Apple Silicon + Intel) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
24 lines
716 B
Swift
24 lines
716 B
Swift
import Foundation
|
||
import CoreFoundation
|
||
|
||
enum StringDecoding {
|
||
|
||
/// 将 GBK/GB18030 编码的 Data 解码为 Swift String
|
||
static func decodeGBK(_ data: Data) -> String {
|
||
guard !data.isEmpty else { return "" }
|
||
if let enc = String.Encoding.gb18030,
|
||
let s = String(data: data, encoding: enc) { return s }
|
||
return String(data: data, encoding: .utf8) ?? ""
|
||
}
|
||
}
|
||
|
||
extension String.Encoding {
|
||
/// GB18030 编码(兼容 GBK / GB2312)
|
||
static var gb18030: String.Encoding? {
|
||
let cf = CFStringConvertEncodingToNSStringEncoding(
|
||
CFStringEncoding(CFStringEncodings.GB_18030_2000.rawValue)
|
||
)
|
||
return String.Encoding(rawValue: cf)
|
||
}
|
||
}
|