Skip to content

Commit 684efe1

Browse files
committed
Move from usascii to utf8
1 parent f27a8e4 commit 684efe1

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/debug.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ pub struct RubyDebugInfo {
1414
impl From<AnyObject> for RubyDebugInfo {
1515
fn from(ao: AnyObject) -> Self {
1616
let object_id = ao.send("object_id", None).send("to_s", None).
17-
try_convert_to::<RString>().unwrap_or(RString::new_usascii_unchecked("Failed to get object_id!")).to_string();
17+
try_convert_to::<RString>().unwrap_or(RString::new_utf8("Failed to get object_id!")).to_string();
1818
let class = ao.send("class", None).send("to_s", None).
19-
try_convert_to::<RString>().unwrap_or(RString::new_usascii_unchecked("Failed to get class!")).to_string();
19+
try_convert_to::<RString>().unwrap_or(RString::new_utf8("Failed to get class!")).to_string();
2020
let inspect = ao.send("inspect", None).
21-
try_convert_to::<RString>().unwrap_or(RString::new_usascii_unchecked("Failed to get inspect!")).to_string();
21+
try_convert_to::<RString>().unwrap_or(RString::new_utf8("Failed to get inspect!")).to_string();
2222

2323
RubyDebugInfo {
2424
object_id: object_id,

src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn anyobject_to_string(item: AnyObject) -> Result<String, RubyDebugInfo> {
3131
if Class::from_existing("Pathname").case_equals(result) {
3232
return Ok(result.instance_variable_get("@path").
3333
try_convert_to::<RString>().
34-
unwrap_or(RString::new_usascii_unchecked("")).
34+
unwrap_or(RString::new_utf8("")).
3535
to_string())
3636
}
3737

src/pathname.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct Pathname {
3939

4040
impl Pathname {
4141
pub fn new(path: &str) -> Pathname {
42-
let arguments = [RString::new_usascii_unchecked(path).to_any_object()];
42+
let arguments = [RString::new_utf8(path).to_any_object()];
4343
let instance = Class::from_existing("Pathname").new_instance(Some(&arguments));
4444

4545
Pathname { value: instance.value() }
@@ -94,7 +94,7 @@ pub fn pn_add_trailing_separator(pth: MaybeString) -> RString {
9494
let x = format!("{}{}", p.to_str(), "a");
9595
match x.rsplit_terminator(MAIN_SEPARATOR).next() {
9696
Some("a") => p,
97-
_ => RString::new_usascii_unchecked(format!("{}{}", p.to_str(), MAIN_SEPARATOR).as_str())
97+
_ => RString::new_utf8(format!("{}{}", p.to_str(), MAIN_SEPARATOR).as_str())
9898
}
9999
}
100100

@@ -105,11 +105,11 @@ pub fn pn_is_absolute(pth: MaybeString) -> Boolean {
105105
// pub fn pn_ascend(){}
106106

107107
pub fn pn_basename(pth: MaybeString, ext: MaybeString) -> RString {
108-
RString::new_usascii_unchecked(basename::basename(to_str(&pth), to_str(&ext)))
108+
RString::new_utf8(basename::basename(to_str(&pth), to_str(&ext)))
109109
}
110110

111111
pub fn pn_children(pth: MaybeString, with_dir: MaybeBoolean) -> Result<AnyObject, Exception> {
112-
let path = pth.unwrap_or(RString::new_usascii_unchecked("."));
112+
let path = pth.unwrap_or(RString::new_utf8("."));
113113
let path = path.to_str();
114114

115115
if let Ok(entries) = fs::read_dir(path) {
@@ -122,12 +122,12 @@ pub fn pn_children(pth: MaybeString, with_dir: MaybeBoolean) -> Result<AnyObject
122122
for entry in entries {
123123
if with_directory {
124124
match entry {
125-
Ok(v) => { arr.push(RString::new_usascii_unchecked(v.path().to_str().unwrap())); },
125+
Ok(v) => { arr.push(RString::new_utf8(v.path().to_str().unwrap())); },
126126
_ => {}
127127
};
128128
} else {
129129
match entry {
130-
Ok(v) => { arr.push(RString::new_usascii_unchecked(v.file_name().to_str().unwrap())); },
130+
Ok(v) => { arr.push(RString::new_utf8(v.file_name().to_str().unwrap())); },
131131
_ => {}
132132
};
133133
}
@@ -173,8 +173,8 @@ pub fn pn_chop_basename(pth: MaybeString) -> AnyObject {
173173
match chop_basename::chop_basename(to_str(&pth)) {
174174
Some((dirname, basename)) => {
175175
let mut arr = Array::with_capacity(2);
176-
arr.push(RString::new_usascii_unchecked(&dirname));
177-
arr.push(RString::new_usascii_unchecked(&basename));
176+
arr.push(RString::new_utf8(&dirname));
177+
arr.push(RString::new_utf8(&basename));
178178
arr.to_any_object()
179179
},
180180
None => NilClass::new().to_any_object()
@@ -184,25 +184,25 @@ pub fn pn_chop_basename(pth: MaybeString) -> AnyObject {
184184
// pub fn pn_cleanpath(pth: MaybeString){}
185185

186186
pub fn pn_cleanpath_aggressive(pth: MaybeString) -> RString {
187-
RString::new_usascii_unchecked(&cleanpath_aggressive::cleanpath_aggressive(to_str(&pth)))
187+
RString::new_utf8(&cleanpath_aggressive::cleanpath_aggressive(to_str(&pth)))
188188
}
189189

190190
pub fn pn_cleanpath_conservative(pth: MaybeString) -> RString {
191-
RString::new_usascii_unchecked(&cleanpath_conservative::cleanpath_conservative(to_str(&pth)))
191+
RString::new_utf8(&cleanpath_conservative::cleanpath_conservative(to_str(&pth)))
192192
}
193193

194194
pub fn pn_del_trailing_separator(pth: MaybeString) -> RString {
195195
{
196196
let path = to_str(&pth);
197197
if path.is_empty() {
198-
return RString::new_usascii_unchecked("/");
198+
return RString::new_utf8("/");
199199
}
200200
let pos = match find_last_non_sep_pos(path.as_bytes()) {
201201
Some(pos) => pos,
202-
None => return RString::new_usascii_unchecked("/"),
202+
None => return RString::new_utf8("/"),
203203
};
204204
if pos != path.len() - 1 {
205-
return RString::new_usascii_unchecked(&path[..pos + 1]);
205+
return RString::new_utf8(&path[..pos + 1]);
206206
}
207207
}
208208
pth.unwrap()
@@ -215,7 +215,7 @@ pub fn pn_is_directory(pth: MaybeString) -> Boolean {
215215
}
216216

217217
pub fn pn_dirname(pth: MaybeString) -> RString {
218-
RString::new_usascii_unchecked(dirname::dirname(to_str(&pth)))
218+
RString::new_utf8(dirname::dirname(to_str(&pth)))
219219
}
220220

221221
// pub fn pn_each_child(){}
@@ -229,11 +229,11 @@ pub fn pn_entries(pth: MaybeString) -> Result<AnyObject, Exception> {
229229
if let Ok(files) = fs::read_dir(path) {
230230
let mut arr = Array::with_capacity(files.size_hint().1.unwrap_or(0) + 2);
231231

232-
arr.push(RString::new_usascii_unchecked("."));
233-
arr.push(RString::new_usascii_unchecked(".."));
232+
arr.push(RString::new_utf8("."));
233+
arr.push(RString::new_utf8(".."));
234234

235235
for file in files {
236-
arr.push(RString::new_usascii_unchecked(file.unwrap().file_name().to_str().unwrap()));
236+
arr.push(RString::new_utf8(file.unwrap().file_name().to_str().unwrap()));
237237
}
238238

239239
Ok(arr.to_any_object())
@@ -263,7 +263,7 @@ pub fn pn_entries_compat(pth: MaybeString) -> Result<AnyObject, Exception> {
263263
}
264264

265265
pub fn pn_extname(pth: MaybeString) -> RString {
266-
RString::new_usascii_unchecked(extname::extname(to_str(&pth)))
266+
RString::new_utf8(extname::extname(to_str(&pth)))
267267
}
268268

269269
// pub fn pn_find(pth: MaybeString, ignore_error: Boolean){}
@@ -298,7 +298,7 @@ pub fn pn_join(args: MaybeArray) -> AnyObject {
298298
// pub fn pn_parent(pth: MaybeString){}
299299

300300
pub fn pn_plus(pth1: MaybeString, pth2: MaybeString) -> RString {
301-
RString::new_usascii_unchecked(&plus::plus_paths(to_str(&pth1), to_str(&pth2)))
301+
RString::new_utf8(&plus::plus_paths(to_str(&pth1), to_str(&pth2)))
302302
}
303303

304304
// pub fn pn_prepend_prefix(prefix: MaybeString, relpath: MaybeString){}

0 commit comments

Comments
 (0)