@@ -5,6 +5,7 @@ use std::str::FromStr;
5
5
use std:: string:: ToString ;
6
6
7
7
use num_traits:: ToPrimitive ;
8
+ use unicode_casing:: CharExt ;
8
9
use unicode_segmentation:: UnicodeSegmentation ;
9
10
10
11
use crate :: format:: { FormatParseError , FormatPart , FormatString } ;
@@ -413,12 +414,12 @@ impl PyString {
413
414
for c in self . value . chars ( ) {
414
415
if c. is_lowercase ( ) {
415
416
if !previous_is_cased {
416
- title. extend ( c. to_uppercase ( ) ) ;
417
+ title. extend ( c. to_titlecase ( ) ) ;
417
418
} else {
418
419
title. push ( c) ;
419
420
}
420
421
previous_is_cased = true ;
421
- } else if c. is_uppercase ( ) {
422
+ } else if c. is_uppercase ( ) || c . is_titlecase ( ) {
422
423
if previous_is_cased {
423
424
title. extend ( c. to_lowercase ( ) ) ;
424
425
} else {
@@ -652,7 +653,7 @@ impl PyString {
652
653
let mut cased = false ;
653
654
let mut previous_is_cased = false ;
654
655
for c in self . value . chars ( ) {
655
- if c. is_uppercase ( ) {
656
+ if c. is_uppercase ( ) || c . is_titlecase ( ) {
656
657
if previous_is_cased {
657
658
return false ;
658
659
}
@@ -1050,6 +1051,7 @@ mod tests {
1050
1051
( "Format,This-As*Title;String" , "fOrMaT,thIs-aS*titLe;String" ) ,
1051
1052
( "Getint" , "getInt" ) ,
1052
1053
( "Greek Ωppercases ..." , "greek ωppercases ..." ) ,
1054
+ ( "Greek ῼitlecases ..." , "greek ῳitlecases ..." ) ,
1053
1055
] ;
1054
1056
for ( title, input) in tests {
1055
1057
assert_eq ! ( PyString :: from( input) . title( & vm) . as_str( ) , title) ;
@@ -1066,6 +1068,7 @@ mod tests {
1066
1068
"A\n Titlecased Line" ,
1067
1069
"A Titlecased, Line" ,
1068
1070
"Greek Ωppercases ..." ,
1071
+ "Greek ῼitlecases ..." ,
1069
1072
] ;
1070
1073
1071
1074
for s in pos {
0 commit comments