Skip to content

Commit 29f9033

Browse files
committed
Change original namespace_from_package_name
1 parent e67ae17 commit 29f9033

File tree

1 file changed

+24
-33
lines changed

1 file changed

+24
-33
lines changed

src/config.rs

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -287,43 +287,35 @@ fn check_if_rescript11_or_higher(version: &str) -> Result<bool, String> {
287287
}
288288

289289
fn namespace_from_package_name(package_name: &str) -> String {
290-
package_name
291-
.to_owned()
292-
.replace('@', "")
293-
.replace('/', "_")
294-
.to_case(Case::Pascal)
295-
}
290+
let len = package_name.len();
291+
let mut buf = String::with_capacity(len);
292+
293+
fn aux(s: &str, capital: bool, buf: &mut String, off: usize) {
294+
if off >= s.len() {
295+
return;
296+
}
296297

297-
impl Config {
298-
fn namespace_of_package_name(s: &str) -> String {
299-
let len = s.len();
300-
let mut buf = String::with_capacity(len);
301-
302-
fn aux(s: &str, capital: bool, buf: &mut String, off: usize) {
303-
if off >= s.len() {
304-
return;
298+
let ch = s.as_bytes()[off] as char;
299+
match ch {
300+
'a'..='z' | 'A'..='Z' | '0'..='9' | '_' => {
301+
let new_capital = false;
302+
buf.push(if capital { ch.to_ascii_uppercase() } else { ch });
303+
aux(s, new_capital, buf, off + 1);
305304
}
306-
307-
let ch = s.as_bytes()[off] as char;
308-
match ch {
309-
'a'..='z' | 'A'..='Z' | '0'..='9' | '_' => {
310-
let new_capital = false;
311-
buf.push(if capital { ch.to_ascii_uppercase() } else { ch });
312-
aux(s, new_capital, buf, off + 1);
313-
}
314-
'/' | '-' => {
315-
aux(s, true, buf, off + 1);
316-
}
317-
_ => {
318-
aux(s, capital, buf, off + 1);
319-
}
305+
'/' | '-' => {
306+
aux(s, true, buf, off + 1);
307+
}
308+
_ => {
309+
aux(s, capital, buf, off + 1);
320310
}
321311
}
322-
323-
aux(s, true, &mut buf, 0);
324-
buf
325312
}
326313

314+
aux(package_name, true, &mut buf, 0);
315+
buf
316+
}
317+
318+
impl Config {
327319
pub fn get_namespace(&self) -> packages::Namespace {
328320
let namespace_from_package = namespace_from_package_name(&self.name);
329321
match (self.namespace.as_ref(), self.namespace_entry.as_ref()) {
@@ -341,8 +333,7 @@ impl Config {
341333
namespace if namespace.is_case(Case::UpperFlat) => {
342334
packages::Namespace::Namespace(namespace.to_string())
343335
}
344-
namespace => packages::Namespace::Namespace(Self::namespace_of_package_name(namespace)),
345-
// namespace.to_string().to_case(Case::Pascal)),
336+
namespace => packages::Namespace::Namespace(namespace_from_package_name(namespace)),
346337
},
347338
(Some(self::NamespaceConfig::String(str)), Some(entry)) => match str.as_str() {
348339
"true" => packages::Namespace::NamespaceWithEntry {

0 commit comments

Comments
 (0)