Old changes

This commit is contained in:
Alex 2022-12-15 13:23:01 +01:00
parent b0bd343188
commit a43b51211a
Signed by: lx
GPG Key ID: 0E496D15096376BE
2 changed files with 21 additions and 0 deletions

View File

@ -84,6 +84,20 @@ impl<'a, 'b> Term<'a, 'b> {
self.0.raw()
}
/// Get the term's raw representation as an str
///
/// Example:
///
/// ```
/// use nettext::dec::decode;
///
/// let term = decode(b"hello { a = x, b = y }").unwrap();
/// assert_eq!(term.raw_str().unwrap(), "hello { a = x, b = y }");
/// ```
pub fn raw_str(&self) -> Result<&'a str, TypeError> {
Ok(std::str::from_utf8(self.0.raw())?)
}
/// If the term is a single string, get that string
///
/// Example:

View File

@ -268,6 +268,13 @@ impl<'a> Term<'a> {
self.0.encode_aux(&mut buf, 0, true);
buf
}
/// Generate the nettext representation of a term, as a String
pub fn encode_string(self) -> String {
unsafe {
String::from_utf8_unchecked(self.encode())
}
}
}
impl<'a> T<'a> {