Skip to content

xiaoyuxlu/r-efi-ucs2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 

Repository files navigation

EFI-UCS2

UCS-2 encoding and decoding library.

Background

This crate is for RustPkg edkii-rust

EFI use UCS2 as default string type. But string type in rust is UTF8. So we create this library for encoding string.

Example

    use efi_ucs2::*;

    let input = "中国";
    let mut buffer = [0u16; 2];
    assert_eq!(encode(input, &mut buffer).is_ok(), true);
    assert_eq!(buffer[0], 0x4e2du16);
    assert_eq!(buffer[1], 0x56fdu16);

    let mut u8_buffer = [0u8; 6];
    let u16_str = [0x4e2du16, 0x56fdu16]; // 中国
    let len = decode(&u16_str, &mut u8_buffer).unwrap_or(0);
    assert_eq!(len, 6);
    assert_eq!(core::str::from_utf8(&u8_buffer[..]), Ok("中国"));

License

MIT License

About

efi-ucs2 crate for encoding and decoding string for EDK2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages