Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Update dependencies and fix clippy lints #84

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ heavyweight = ['regex', 'lazy_static']
name = "inflector"

[dependencies]
regex = {version = "1.1", optional = true}
lazy_static = {version = "1.2.0", optional = true}
regex = { version = "1.5.4", optional = true }
lazy_static = { version = "1.4.0", optional = true }
14 changes: 7 additions & 7 deletions src/cases/camelcase/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![deny(warnings)]
use cases::case::*;
use crate::cases::case::*;

/// Converts a `&str` to camelCase `String`
///
Expand Down Expand Up @@ -84,7 +84,7 @@ pub fn to_camel_case(non_camelized_string: &str) -> String {
has_seperator: false,
inverted: false,
};
to_case_camel_like(&non_camelized_string, options)
to_case_camel_like(non_camelized_string, options)
}

/// Determines if a `&str` is camelCase bool``
Expand Down Expand Up @@ -168,7 +168,7 @@ pub fn to_camel_case(non_camelized_string: &str) -> String {
/// assert!(asserted_bool == false);
/// ```
pub fn is_camel_case(test_string: &str) -> bool {
to_camel_case(&test_string.clone()) == test_string
to_camel_case(test_string) == test_string
}

#[cfg(all(feature = "unstable", test))]
Expand Down Expand Up @@ -211,8 +211,8 @@ mod benchmarks {

#[cfg(test)]
mod tests {
use ::to_camel_case;
use ::is_camel_case;
use crate::is_camel_case;
use crate::to_camel_case;

#[test]
fn from_camel_case() {
Expand Down Expand Up @@ -307,7 +307,8 @@ mod tests {

#[test]
fn wrapped_in_bad_chars() {
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
let convertable_string: String =
"-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
let expected: String = "wrappedInBadChars".to_owned();
assert_eq!(to_camel_case(&convertable_string), expected)
}
Expand Down Expand Up @@ -367,4 +368,3 @@ mod tests {
assert_eq!(is_camel_case(&convertable_string), false)
}
}

107 changes: 78 additions & 29 deletions src/cases/case/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![deny(warnings)]
#[allow(unknown_lints)]
#[allow(unused_imports)]
#![allow(unknown_lints)]
#![allow(unused_imports)]
use std::ascii::*;

pub struct CamelOptions {
Expand All @@ -19,9 +19,9 @@ pub fn to_case_snake_like(convertable_string: &str, replace_with: &str, case: &s
if char_is_seperator(&char_with_index.1) {
if !first_character {
first_character = true;
result.push(replace_with.chars().nth(0).unwrap_or('_'));
result.push(replace_with.chars().next().unwrap_or('_'));
}
} else if requires_seperator(char_with_index, first_character, &convertable_string) {
} else if requires_seperator(char_with_index, first_character, convertable_string) {
first_character = false;
result = snake_like_with_seperator(result, replace_with, &char_with_index.1, case)
} else {
Expand Down Expand Up @@ -62,7 +62,12 @@ pub fn to_case_camel_like(convertable_string: &str, camel_options: CamelOptions)
}

#[inline]
fn append_on_new_word(mut result: String, first_word: bool, character: char, camel_options: &CamelOptions) -> String {
fn append_on_new_word(
mut result: String,
first_word: bool,
character: char,
camel_options: &CamelOptions,
) -> String {
if not_first_word_and_has_seperator(first_word, camel_options.has_seperator) {
result.push(camel_options.injectable_char);
}
Expand All @@ -82,11 +87,12 @@ fn first_word_or_not_inverted(first_word: bool, inverted: bool) -> bool {
!inverted || first_word
}


fn last_char_lower_current_is_upper_or_new_word(new_word: bool, last_char: char, character: char) -> bool{
new_word ||
((last_char.is_lowercase() && character.is_uppercase()) &&
(last_char != ' '))
fn last_char_lower_current_is_upper_or_new_word(
new_word: bool,
last_char: char,
character: char,
) -> bool {
new_word || ((last_char.is_lowercase() && character.is_uppercase()) && (last_char != ' '))
}

fn char_is_seperator(character: &char) -> bool {
Expand All @@ -102,10 +108,14 @@ fn is_not_alphanumeric(character: char) -> bool {
}

#[inline]
fn requires_seperator(char_with_index: (usize, char), first_character: bool, convertable_string: &str) -> bool {
!first_character &&
char_is_uppercase(char_with_index.1) &&
next_or_previous_char_is_lowercase(convertable_string, char_with_index.0)
fn requires_seperator(
char_with_index: (usize, char),
first_character: bool,
convertable_string: &str,
) -> bool {
!first_character
&& char_is_uppercase(char_with_index.1)
&& next_or_previous_char_is_lowercase(convertable_string, char_with_index.0)
}

#[inline]
Expand All @@ -120,21 +130,34 @@ fn snake_like_no_seperator(mut accumlator: String, current_char: &char, case: &s
}

#[inline]
fn snake_like_with_seperator(mut accumlator: String, replace_with: &str, current_char: &char, case: &str) -> String {
fn snake_like_with_seperator(
mut accumlator: String,
replace_with: &str,
current_char: &char,
case: &str,
) -> String {
if case == "lower" {
accumlator.push(replace_with.chars().nth(0).unwrap_or('_'));
accumlator.push(replace_with.chars().next().unwrap_or('_'));
accumlator.push(current_char.to_ascii_lowercase());
accumlator
} else {
accumlator.push(replace_with.chars().nth(0).unwrap_or('_'));
accumlator.push(replace_with.chars().next().unwrap_or('_'));
accumlator.push(current_char.to_ascii_uppercase());
accumlator
}
}

fn next_or_previous_char_is_lowercase(convertable_string: &str, char_with_index: usize) -> bool {
convertable_string.chars().nth(char_with_index + 1).unwrap_or('A').is_lowercase() ||
convertable_string.chars().nth(char_with_index - 1).unwrap_or('A').is_lowercase()
convertable_string
.chars()
.nth(char_with_index + 1)
.unwrap_or('A')
.is_lowercase()
|| convertable_string
.chars()
.nth(char_with_index - 1)
.unwrap_or('A')
.is_lowercase()
}

fn char_is_uppercase(test_char: char) -> bool {
Expand All @@ -161,7 +184,6 @@ fn test_is_not_alphanumeric_on_is_not_alphanumeric() {
assert!(is_not_alphanumeric('_'))
}


#[test]
fn test_char_is_uppercase_when_it_is() {
assert_eq!(char_is_uppercase('A'), true)
Expand All @@ -184,22 +206,34 @@ fn test_next_or_previous_char_is_lowercase_false() {

#[test]
fn snake_like_with_seperator_lowers() {
assert_eq!(snake_like_with_seperator("".to_owned(), "^", &'c', "lower"), "^c".to_string())
assert_eq!(
snake_like_with_seperator("".to_owned(), "^", &'c', "lower"),
"^c".to_string()
)
}

#[test]
fn snake_like_with_seperator_upper() {
assert_eq!(snake_like_with_seperator("".to_owned(), "^", &'c', "upper"), "^C".to_string())
assert_eq!(
snake_like_with_seperator("".to_owned(), "^", &'c', "upper"),
"^C".to_string()
)
}

#[test]
fn snake_like_no_seperator_lower() {
assert_eq!(snake_like_no_seperator("".to_owned(), &'C', "lower"), "c".to_string())
assert_eq!(
snake_like_no_seperator("".to_owned(), &'C', "lower"),
"c".to_string()
)
}

#[test]
fn snake_like_no_seperator_upper() {
assert_eq!(snake_like_no_seperator("".to_owned(), &'c', "upper"), "C".to_string())
assert_eq!(
snake_like_no_seperator("".to_owned(), &'c', "upper"),
"C".to_string()
)
}

#[test]
Expand Down Expand Up @@ -249,27 +283,42 @@ fn test_char_is_seperator_when_not() {

#[test]
fn test_last_char_lower_current_is_upper_or_new_word_with_new_word() {
assert_eq!(last_char_lower_current_is_upper_or_new_word(true, ' ', '-'), true)
assert_eq!(
last_char_lower_current_is_upper_or_new_word(true, ' ', '-'),
true
)
}

#[test]
fn test_last_char_lower_current_is_upper_or_new_word_last_char_space() {
assert_eq!(last_char_lower_current_is_upper_or_new_word(false, ' ', '-'), false)
assert_eq!(
last_char_lower_current_is_upper_or_new_word(false, ' ', '-'),
false
)
}

#[test]
fn test_last_char_lower_current_is_upper_or_new_word_last_char_lower_current_upper() {
assert_eq!(last_char_lower_current_is_upper_or_new_word(false, 'a', 'A'), true)
assert_eq!(
last_char_lower_current_is_upper_or_new_word(false, 'a', 'A'),
true
)
}

#[test]
fn test_last_char_lower_current_is_upper_or_new_word_last_char_upper_current_upper() {
assert_eq!(last_char_lower_current_is_upper_or_new_word(false, 'A', 'A'), false)
assert_eq!(
last_char_lower_current_is_upper_or_new_word(false, 'A', 'A'),
false
)
}

#[test]
fn test_last_char_lower_current_is_upper_or_new_word_last_char_upper_current_lower() {
assert_eq!(last_char_lower_current_is_upper_or_new_word(false, 'A', 'a'), false)
assert_eq!(
last_char_lower_current_is_upper_or_new_word(false, 'A', 'a'),
false
)
}

#[test]
Expand Down
14 changes: 7 additions & 7 deletions src/cases/classcase/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![deny(warnings)]
use cases::case::*;
use crate::cases::case::*;
#[cfg(feature = "heavyweight")]
use string::singularize::to_singular;
use crate::string::singularize::to_singular;
#[cfg(feature = "heavyweight")]
/// Converts a `&str` to `ClassCase` `String`
///
Expand Down Expand Up @@ -193,7 +193,7 @@ pub fn to_class_case(non_class_case_string: &str) -> String {
///
/// ```
pub fn is_class_case(test_string: &str) -> bool {
to_class_case(&test_string.clone()) == test_string
to_class_case(test_string) == test_string
}

#[cfg(all(feature = "unstable", test))]
Expand Down Expand Up @@ -221,8 +221,8 @@ mod benchmarks {
#[cfg(test)]
#[cfg(feature = "heavyweight")]
mod tests {
use ::to_class_case;
use ::is_class_case;
use crate::is_class_case;
use crate::to_class_case;

#[test]
fn from_camel_case() {
Expand Down Expand Up @@ -324,7 +324,8 @@ mod tests {

#[test]
fn wrapped_in_bad_chars() {
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
let convertable_string: String =
"-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
let expected: String = "WrappedInBadChar".to_owned();
assert_eq!(to_class_case(&convertable_string), expected)
}
Expand Down Expand Up @@ -390,4 +391,3 @@ mod tests {
assert_eq!(is_class_case(&convertable_string), true)
}
}

9 changes: 4 additions & 5 deletions src/cases/kebabcase/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![deny(warnings)]
use cases::case::*;
use crate::cases::case::*;
/// Determines if a `&str` is `kebab-case`
///
/// ```
Expand Down Expand Up @@ -58,7 +58,7 @@ use cases::case::*;
///
/// ```
pub fn is_kebab_case(test_string: &str) -> bool {
test_string == to_kebab_case(test_string.clone())
test_string == to_kebab_case(test_string)
}

/// Converts a `&str` to `kebab-case` `String`
Expand Down Expand Up @@ -152,8 +152,8 @@ mod benchmarks {

#[cfg(test)]
mod tests {
use ::to_kebab_case;
use ::is_kebab_case;
use crate::is_kebab_case;
use crate::to_kebab_case;

#[test]
fn from_camel_case() {
Expand Down Expand Up @@ -259,4 +259,3 @@ mod tests {
assert_eq!(is_kebab_case(&convertable_string), false)
}
}

11 changes: 6 additions & 5 deletions src/cases/pascalcase/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![deny(warnings)]
use cases::case::*;
use crate::cases::case::*;
/// Converts a `&str` to pascalCase `String`
///
/// ```
Expand Down Expand Up @@ -159,7 +159,7 @@ pub fn to_pascal_case(non_pascalized_string: &str) -> String {
/// assert!(asserted_bool == false);
/// ```
pub fn is_pascal_case(test_string: &str) -> bool {
to_pascal_case(test_string.clone()) == test_string
to_pascal_case(test_string) == test_string
}

#[cfg(all(feature = "unstable", test))]
Expand Down Expand Up @@ -202,8 +202,8 @@ mod benchmarks {

#[cfg(test)]
mod tests {
use ::to_pascal_case;
use ::is_pascal_case;
use crate::is_pascal_case;
use crate::to_pascal_case;

#[test]
fn from_camel_case() {
Expand Down Expand Up @@ -298,7 +298,8 @@ mod tests {

#[test]
fn wrapped_in_bad_chars() {
let convertable_string: String = "-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
let convertable_string: String =
"-!#$%wrapped in bad chars&*^*&(&*^&(<><?>><?><>))".to_owned();
let expected: String = "WrappedInBadChars".to_owned();
assert_eq!(to_pascal_case(&convertable_string), expected)
}
Expand Down
Loading