hwpers 0.5.0

A Rust library for parsing Korean Hangul Word Processor (HWP) files with full layout rendering support
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::error::{HwpError, Result};
use encoding_rs::UTF_16LE;

pub fn utf16le_to_string(data: &[u8]) -> Result<String> {
    let (cow, _, had_errors) = UTF_16LE.decode(data);
    if had_errors {
        return Err(HwpError::EncodingError("Invalid UTF-16LE data".to_string()));
    }
    Ok(cow.into_owned())
}

pub fn string_to_utf16le(s: &str) -> Vec<u8> {
    let mut result = Vec::new();
    for ch in s.encode_utf16() {
        result.extend_from_slice(&ch.to_le_bytes());
    }
    result
}