Old changes
This commit is contained in:
parent
b0bd343188
commit
a43b51211a
2 changed files with 21 additions and 0 deletions
|
@ -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:
|
||||
|
|
|
@ -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> {
|
||||
|
|
Loading…
Reference in a new issue