strings bro

This commit is contained in:
abbie 2022-03-31 17:18:16 +01:00
parent f51e4ac941
commit 37bd4f2166
No known key found for this signature in database
GPG key ID: 04DDE463F9200F87
2 changed files with 14 additions and 1 deletions

View file

@ -1,7 +1,7 @@
[package] [package]
name = "clippet" name = "clippet"
description = "Provides a teeny way to have some nice byte structures that's easy to use." description = "Provides a teeny way to have some nice byte structures that's easy to use."
version = "0.1.7" version = "0.1.8"
edition = "2021" edition = "2021"
authors = ["Celeste <colean@colean.cc>"] authors = ["Celeste <colean@colean.cc>"]
license = "MPL-2.0" license = "MPL-2.0"

View file

@ -84,6 +84,19 @@ impl Clippet {
pub fn get_data(&self, index: usize) -> BytesMut { pub fn get_data(&self, index: usize) -> BytesMut {
return self.data[index].to_owned() return self.data[index].to_owned()
} }
/// Takes an indexed byte sequence and returns it as a String.
/// ```no_run
/// let bytes = BytesMut::from("Hello, world!");
/// let mut data = Clippet { ... };
/// data.add_bytes(bytes);
/// assert_eq!(data.get_as_string(0), "Hello, world!");
/// ```
pub fn get_as_string(&self, index: usize) -> String {
let bytes = self.get_data(index);
let y = bytes.as_ref();
let x = String::from_utf8_lossy(y).to_string();
return x
}
/// Takes a filename and splits it into sequences of bytes within a Clippet. /// Takes a filename and splits it into sequences of bytes within a Clippet.
/// It is recommended to use smaller byte sequences, however this is user-configurable. /// It is recommended to use smaller byte sequences, however this is user-configurable.
/// ///