refactor: replace read_cur_shift_jis with encoding_rs::SHIFT_JIS
This commit is contained in:
parent
ef1b819881
commit
bb10cdb4ee
|
@ -3,16 +3,15 @@ use std::io;
|
|||
use std::io::{BufRead, BufReader, Cursor, Read};
|
||||
use std::sync::Arc;
|
||||
|
||||
use byteorder::{LE, ReadBytesExt};
|
||||
use byteorder::{ReadBytesExt, LE};
|
||||
|
||||
use crate::common::{Color, Rect};
|
||||
use crate::framework::context::Context;
|
||||
use crate::framework::error::{GameError, GameResult};
|
||||
use crate::framework::error::GameError::ResourceLoadError;
|
||||
use crate::framework::error::{GameError, GameResult};
|
||||
use crate::framework::filesystem;
|
||||
use crate::game::shared_game_state::TileSize;
|
||||
use crate::game::stage::{PxPackScroll, PxPackStageData, StageData};
|
||||
use crate::util::encoding::read_cur_shift_jis;
|
||||
|
||||
static SUPPORTED_PXM_VERSIONS: [u8; 1] = [0x10];
|
||||
static SUPPORTED_PXE_VERSIONS: [u8; 2] = [0, 0x10];
|
||||
|
@ -88,18 +87,7 @@ impl Map {
|
|||
let mut raw_chars = Vec::new();
|
||||
raw_chars.resize(bytes as usize, 0u8);
|
||||
map_data.read(&mut raw_chars)?;
|
||||
let mut raw_chars = Cursor::new(raw_chars);
|
||||
|
||||
let mut chars = Vec::new();
|
||||
chars.reserve(bytes as usize);
|
||||
|
||||
while bytes > 0 {
|
||||
let (consumed, chr) = read_cur_shift_jis(&mut raw_chars, bytes);
|
||||
chars.push(chr);
|
||||
bytes -= consumed;
|
||||
}
|
||||
|
||||
Ok(chars.iter().collect())
|
||||
Ok(encoding_rs::SHIFT_JIS.decode_without_bom_handling(&raw_chars).0.into_owned())
|
||||
}
|
||||
|
||||
fn skip_string<R: io::Read>(map_data: &mut R) -> GameResult {
|
||||
|
@ -211,7 +199,7 @@ impl Map {
|
|||
log::warn!("Map attribute data is shorter than 256 bytes!");
|
||||
}
|
||||
} else if let Ok(mut attrib_data) =
|
||||
filesystem::open_find(ctx, roots, ["Stage/", &tileset_fg, ".pxattr"].join(""))
|
||||
filesystem::open_find(ctx, roots, ["Stage/", &tileset_fg, ".pxattr"].join(""))
|
||||
{
|
||||
attrib_data.read_exact(&mut magic)?;
|
||||
|
||||
|
@ -549,7 +537,7 @@ impl WaterParams {
|
|||
}
|
||||
|
||||
pub fn load_from<R: io::Read>(&mut self, data: R) -> GameResult {
|
||||
fn next_u8<'a>(s: &mut impl Iterator<Item=&'a str>, error_msg: &str) -> GameResult<u8> {
|
||||
fn next_u8<'a>(s: &mut impl Iterator<Item = &'a str>, error_msg: &str) -> GameResult<u8> {
|
||||
match s.next() {
|
||||
None => Err(GameError::ParseError("Out of range.".to_string())),
|
||||
Some(v) => v.trim().parse::<u8>().map_err(|_| GameError::ParseError(error_msg.to_string())),
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
use std::io::{Cursor, Read};
|
||||
use std::str::from_utf8;
|
||||
|
||||
use byteorder::LE;
|
||||
use byteorder::ReadBytesExt;
|
||||
use byteorder::LE;
|
||||
use log::info;
|
||||
|
||||
use crate::common::Color;
|
||||
use crate::engine_constants::EngineConstants;
|
||||
use crate::framework::context::Context;
|
||||
use crate::framework::error::{GameError, GameResult};
|
||||
use crate::framework::error::GameError::ResourceLoadError;
|
||||
use crate::framework::error::{GameError, GameResult};
|
||||
use crate::framework::filesystem;
|
||||
use crate::game::map::{Map, NPCData};
|
||||
use crate::game::scripting::tsc::text_script::TextScript;
|
||||
use crate::util::encoding::read_cur_shift_jis;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct NpcType {
|
||||
|
@ -262,17 +261,7 @@ fn zero_index(s: &[u8]) -> usize {
|
|||
}
|
||||
|
||||
fn from_shift_jis(s: &[u8]) -> String {
|
||||
let mut cursor = Cursor::new(s);
|
||||
let mut chars = Vec::new();
|
||||
let mut bytes = s.len() as u32;
|
||||
|
||||
while bytes > 0 {
|
||||
let (consumed, chr) = read_cur_shift_jis(&mut cursor, bytes);
|
||||
chars.push(chr);
|
||||
bytes -= consumed;
|
||||
}
|
||||
|
||||
chars.iter().collect()
|
||||
encoding_rs::SHIFT_JIS.decode_without_bom_handling(s).0.into_owned()
|
||||
}
|
||||
|
||||
fn from_csplus_stagetbl(s: &[u8], is_switch: bool) -> String {
|
||||
|
|
7329
src/util/encoding.rs
7329
src/util/encoding.rs
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,3 @@
|
|||
pub mod bitvec;
|
||||
pub mod encoding;
|
||||
pub mod rng;
|
||||
pub mod browser;
|
||||
pub mod rng;
|
||||
|
|
Loading…
Reference in New Issue