Skip to content

Commit

Permalink
update to 2018 edition
Browse files Browse the repository at this point in the history
- Brings MSRV support up to 1.31.
- Removes the build.rs file.
  • Loading branch information
seanmonstar committed Oct 18, 2024
1 parent 8dc84ec commit 8c778c7
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
- name: Install Rust MSRV
uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.3.0
toolchain: 1.36.0

- name: Check
run: cargo build
Expand Down
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ license = "MIT OR Apache-2.0"
readme = "README.md"
keywords = ["lowercase", "case", "case-insensitive", "case-folding", "no_std"]
categories = ["internationalization", "text-processing", "no-std"]
edition = "2018"

exclude = [
"scripts/*"
]

build = "build.rs"

[build-dependencies]
version_check = "0.9"

[features]
nightly = []
23 changes: 0 additions & 23 deletions build.rs

This file was deleted.

31 changes: 5 additions & 26 deletions src/ascii.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,27 @@
use alloc::string::String;
#[cfg(__unicase__iter_cmp)]
use core::cmp::Ordering;
use core::fmt;
use core::hash::{Hash, Hasher};
use core::ops::{Deref, DerefMut};
use core::str::FromStr;
#[cfg(not(__unicase__core_and_alloc))]
#[allow(deprecated, unused)]
use std::ascii::AsciiExt;

use super::{Ascii, Encoding, UniCase};

impl<S> Ascii<S> {
#[inline]
#[cfg(__unicase__const_fns)]
pub const fn new(s: S) -> Ascii<S> {
Ascii(s)
}

/// Construct a new `Ascii`.
///
/// For Rust versions >= 1.31, this is a `const fn`.
#[inline]
#[cfg(not(__unicase__const_fns))]
pub fn new(s: S) -> Ascii<S> {
pub const fn new(s: S) -> Ascii<S> {
Ascii(s)
}

#[cfg(__unicase_const_fns)]
/// Convert this into a [`UniCase`].
pub const fn into_unicase(self) -> UniCase<S> {
UniCase(Encoding::Ascii(self))
}

#[cfg(not(__unicase_const_fns))]
pub fn into_unicase(self) -> UniCase<S> {
UniCase(Encoding::Ascii(self))
}

/// Consume this `Ascii` and get the inner value.
#[inline]
pub fn into_inner(self) -> S {
self.0
Expand All @@ -58,15 +43,13 @@ impl<S> DerefMut for Ascii<S> {
}
}

#[cfg(__unicase__iter_cmp)]
impl<T: AsRef<str>> PartialOrd for Ascii<T> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

#[cfg(__unicase__iter_cmp)]
impl<T: AsRef<str>> Ord for Ascii<T> {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
Expand Down Expand Up @@ -131,12 +114,10 @@ impl<S: AsRef<str>> Hash for Ascii<S> {

#[cfg(test)]
mod tests {
#[cfg(__unicase__default_hasher)]
use super::Ascii;
use std::collections::hash_map::DefaultHasher;
#[cfg(not(__unicase__default_hasher))]
use std::hash::SipHasher as DefaultHasher;
use std::hash::{Hash, Hasher};
use Ascii;
use std::string::String;

fn hash<T: Hash>(t: &T) -> u64 {
let mut s = DefaultHasher::new();
Expand Down Expand Up @@ -165,7 +146,6 @@ mod tests {
b.iter(|| assert_eq!(Ascii("foobar"), Ascii("FOOBAR")));
}

#[cfg(__unicase__iter_cmp)]
#[test]
fn test_case_cmp() {
assert!(Ascii("foobar") == Ascii("FOOBAR"));
Expand All @@ -178,7 +158,6 @@ mod tests {
assert!(Ascii("a") < Ascii("AA"));
}

#[cfg(__unicase__const_fns)]
#[test]
fn test_ascii_new_const() {
const _ASCII: Ascii<&'static str> = Ascii::new("");
Expand Down
48 changes: 5 additions & 43 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![cfg_attr(test, deny(missing_docs))]
#![cfg_attr(test, deny(warnings))]
#![doc(html_root_url = "https://docs.rs/unicase/2.7.0")]
#![cfg_attr(feature = "nightly", feature(test))]
#![cfg_attr(all(__unicase__core_and_alloc, not(test),), no_std)]
#![no_std]

//! # UniCase
//!
Expand Down Expand Up @@ -43,21 +42,15 @@
//! assert_eq!(a, b);
//! ```
#[cfg(test)]
extern crate std;
#[cfg(feature = "nightly")]
extern crate test;

#[cfg(all(__unicase__core_and_alloc, not(test)))]
extern crate alloc;
#[cfg(all(__unicase__core_and_alloc, not(test)))]
use alloc::string::String;

#[cfg(not(all(__unicase__core_and_alloc, not(test))))]
extern crate std as alloc;
#[cfg(not(all(__unicase__core_and_alloc, not(test))))]
extern crate std as core;

use alloc::borrow::Cow;
#[cfg(__unicase__iter_cmp)]
use core::cmp::Ordering;
use core::fmt;
use core::hash::{Hash, Hasher};
Expand Down Expand Up @@ -128,10 +121,6 @@ impl<S: AsRef<str>> UniCase<S> {
///
/// Note: This scans the text to determine if it is all ASCII or not.
pub fn new(s: S) -> UniCase<S> {
#[cfg(not(__unicase__core_and_alloc))]
#[allow(deprecated, unused)]
use std::ascii::AsciiExt;

if s.as_ref().is_ascii() {
UniCase(Encoding::Ascii(Ascii(s)))
} else {
Expand All @@ -147,10 +136,6 @@ impl<S: AsRef<str>> UniCase<S> {
/// Unicode Case Folding is meant for string storage and matching, not for
/// display.
pub fn to_folded_case(&self) -> String {
#[cfg(not(__unicase__core_and_alloc))]
#[allow(deprecated, unused)]
use std::ascii::AsciiExt;

match self.0 {
Encoding::Ascii(ref s) => s.0.as_ref().to_ascii_lowercase(),
Encoding::Unicode(ref s) => s.to_folded_case(),
Expand All @@ -160,33 +145,15 @@ impl<S: AsRef<str>> UniCase<S> {

impl<S> UniCase<S> {
/// Creates a new `UniCase`, skipping the ASCII check.
#[cfg(__unicase__const_fns)]
pub const fn unicode(s: S) -> UniCase<S> {
UniCase(Encoding::Unicode(Unicode(s)))
}

/// Creates a new `UniCase`, skipping the ASCII check.
///
/// For Rust versions >= 1.31, this is a `const fn`.
#[cfg(not(__unicase__const_fns))]
pub fn unicode(s: S) -> UniCase<S> {
UniCase(Encoding::Unicode(Unicode(s)))
}

/// Creates a new `UniCase` which performs only ASCII case folding.
#[cfg(__unicase__const_fns)]
pub const fn ascii(s: S) -> UniCase<S> {
UniCase(Encoding::Ascii(Ascii(s)))
}

/// Creates a new `UniCase` which performs only ASCII case folding.
///
/// For Rust versions >= 1.31, this is a `const fn`.
#[cfg(not(__unicase__const_fns))]
pub fn ascii(s: S) -> UniCase<S> {
UniCase(Encoding::Ascii(Ascii(s)))
}

/// Return `true` if this instance will only perform ASCII case folding.
pub fn is_ascii(&self) -> bool {
match self.0 {
Expand Down Expand Up @@ -308,15 +275,13 @@ into_impl!(&'a str);
into_impl!(String);
into_impl!(Cow<'a, str>);

#[cfg(__unicase__iter_cmp)]
impl<T: AsRef<str>> PartialOrd for UniCase<T> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

#[cfg(__unicase__iter_cmp)]
impl<T: AsRef<str>> Ord for UniCase<T> {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
Expand All @@ -343,11 +308,10 @@ impl<S: FromStr + AsRef<str>> FromStr for UniCase<S> {
#[cfg(test)]
mod tests {
use super::UniCase;
#[cfg(__unicase__default_hasher)]
use std::borrow::ToOwned;
use std::collections::hash_map::DefaultHasher;
#[cfg(not(__unicase__default_hasher))]
use std::hash::SipHasher as DefaultHasher;
use std::hash::{Hash, Hasher};
use std::string::String;

fn hash<T: Hash>(t: &T) -> u64 {
let mut s = DefaultHasher::new();
Expand Down Expand Up @@ -432,7 +396,6 @@ mod tests {
b.iter(|| assert!(::std::str::from_utf8(SUBJECT).is_ok()));
}

#[cfg(__unicase__iter_cmp)]
#[test]
fn test_case_cmp() {
assert!(UniCase::new("a") < UniCase::new("B"));
Expand Down Expand Up @@ -467,7 +430,6 @@ mod tests {
let _: &str = owned.as_ref();
}

#[cfg(__unicase__const_fns)]
#[test]
fn test_unicase_unicode_const() {
const _UNICASE: UniCase<&'static str> = UniCase::unicode("");
Expand Down
2 changes: 2 additions & 0 deletions src/unicode/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ pub fn lookup(orig: char) -> Fold {

#[test]
fn lookup_consistency() {
use std::vec::Vec;

fn lookup_naive(orig: char) -> Fold {
let single_char = match orig as u32 {
0x0041 => 0x0061,
Expand Down
4 changes: 0 additions & 4 deletions src/unicode/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#[cfg(all(__unicase__core_and_alloc, not(test)))]
use alloc::string::String;
#[cfg(__unicase__iter_cmp)]
use core::cmp::Ordering;
use core::hash::{Hash, Hasher};

Expand Down Expand Up @@ -43,15 +41,13 @@ impl<S1: AsRef<str>, S2: AsRef<str>> PartialEq<Unicode<S2>> for Unicode<S1> {

impl<S: AsRef<str>> Eq for Unicode<S> {}

#[cfg(__unicase__iter_cmp)]
impl<T: AsRef<str>> PartialOrd for Unicode<T> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

#[cfg(__unicase__iter_cmp)]
impl<T: AsRef<str>> Ord for Unicode<T> {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
Expand Down

0 comments on commit 8c778c7

Please sign in to comment.