@@ -909,7 +909,7 @@ impl PrimitiveValue {
909
909
{
910
910
match self {
911
911
PrimitiveValue :: Str ( s) => {
912
- s. trim ( )
912
+ s. trim_matches ( whitespace_or_null )
913
913
. parse ( )
914
914
. context ( ParseIntegerSnafu )
915
915
. map_err ( |err| ConvertValueError {
@@ -919,7 +919,7 @@ impl PrimitiveValue {
919
919
} )
920
920
}
921
921
PrimitiveValue :: Strs ( s) if !s. is_empty ( ) => s[ 0 ]
922
- . trim ( )
922
+ . trim_matches ( whitespace_or_null )
923
923
. parse ( )
924
924
. context ( ParseIntegerSnafu )
925
925
. map_err ( |err| ConvertValueError {
@@ -1078,7 +1078,7 @@ impl PrimitiveValue {
1078
1078
match self {
1079
1079
PrimitiveValue :: Empty => Ok ( Vec :: new ( ) ) ,
1080
1080
PrimitiveValue :: Str ( s) => {
1081
- let out = s. trim ( ) . parse ( ) . context ( ParseIntegerSnafu ) . map_err ( |err| {
1081
+ let out = s. trim_matches ( whitespace_or_null ) . parse ( ) . context ( ParseIntegerSnafu ) . map_err ( |err| {
1082
1082
ConvertValueError {
1083
1083
requested : "integer" ,
1084
1084
original : self . value_type ( ) ,
@@ -1090,7 +1090,7 @@ impl PrimitiveValue {
1090
1090
PrimitiveValue :: Strs ( s) => {
1091
1091
s. iter ( )
1092
1092
. map ( |v| {
1093
- v. trim ( ) . parse ( ) . context ( ParseIntegerSnafu ) . map_err ( |err| {
1093
+ v. trim_matches ( whitespace_or_null ) . parse ( ) . context ( ParseIntegerSnafu ) . map_err ( |err| {
1094
1094
ConvertValueError {
1095
1095
requested : "integer" ,
1096
1096
original : self . value_type ( ) ,
@@ -1256,7 +1256,7 @@ impl PrimitiveValue {
1256
1256
pub fn to_float32 ( & self ) -> Result < f32 , ConvertValueError > {
1257
1257
match self {
1258
1258
PrimitiveValue :: Str ( s) => {
1259
- s. trim ( )
1259
+ s. trim_matches ( whitespace_or_null )
1260
1260
. parse ( )
1261
1261
. context ( ParseFloatSnafu )
1262
1262
. map_err ( |err| ConvertValueError {
@@ -1266,7 +1266,7 @@ impl PrimitiveValue {
1266
1266
} )
1267
1267
}
1268
1268
PrimitiveValue :: Strs ( s) if !s. is_empty ( ) => s[ 0 ]
1269
- . trim ( )
1269
+ . trim_matches ( whitespace_or_null )
1270
1270
. parse ( )
1271
1271
. context ( ParseFloatSnafu )
1272
1272
. map_err ( |err| ConvertValueError {
@@ -1426,7 +1426,7 @@ impl PrimitiveValue {
1426
1426
PrimitiveValue :: Empty => Ok ( Vec :: new ( ) ) ,
1427
1427
PrimitiveValue :: Str ( s) => {
1428
1428
let out =
1429
- s. trim ( )
1429
+ s. trim_matches ( whitespace_or_null )
1430
1430
. parse ( )
1431
1431
. context ( ParseFloatSnafu )
1432
1432
. map_err ( |err| ConvertValueError {
@@ -1439,7 +1439,7 @@ impl PrimitiveValue {
1439
1439
PrimitiveValue :: Strs ( s) => s
1440
1440
. iter ( )
1441
1441
. map ( |v| {
1442
- v. trim ( )
1442
+ v. trim_matches ( whitespace_or_null )
1443
1443
. parse ( )
1444
1444
. context ( ParseFloatSnafu )
1445
1445
. map_err ( |err| ConvertValueError {
@@ -1622,7 +1622,7 @@ impl PrimitiveValue {
1622
1622
pub fn to_float64 ( & self ) -> Result < f64 , ConvertValueError > {
1623
1623
match self {
1624
1624
PrimitiveValue :: Str ( s) => {
1625
- s. trim ( )
1625
+ s. trim_matches ( whitespace_or_null )
1626
1626
. parse ( )
1627
1627
. context ( ParseFloatSnafu )
1628
1628
. map_err ( |err| ConvertValueError {
@@ -1632,7 +1632,7 @@ impl PrimitiveValue {
1632
1632
} )
1633
1633
}
1634
1634
PrimitiveValue :: Strs ( s) if !s. is_empty ( ) => s[ 0 ]
1635
- . trim ( )
1635
+ . trim_matches ( whitespace_or_null )
1636
1636
. parse ( )
1637
1637
. context ( ParseFloatSnafu )
1638
1638
. map_err ( |err| ConvertValueError {
@@ -1791,7 +1791,7 @@ impl PrimitiveValue {
1791
1791
match self {
1792
1792
PrimitiveValue :: Str ( s) => {
1793
1793
let out =
1794
- s. trim ( )
1794
+ s. trim_matches ( whitespace_or_null )
1795
1795
. parse ( )
1796
1796
. context ( ParseFloatSnafu )
1797
1797
. map_err ( |err| ConvertValueError {
@@ -1804,7 +1804,7 @@ impl PrimitiveValue {
1804
1804
PrimitiveValue :: Strs ( s) => s
1805
1805
. iter ( )
1806
1806
. map ( |v| {
1807
- v. trim ( )
1807
+ v. trim_matches ( whitespace_or_null )
1808
1808
. parse ( )
1809
1809
. context ( ParseFloatSnafu )
1810
1810
. map_err ( |err| ConvertValueError {
@@ -2104,7 +2104,7 @@ impl PrimitiveValue {
2104
2104
original : self . value_type ( ) ,
2105
2105
cause : Some ( Box :: from ( err) ) ,
2106
2106
} ) ,
2107
- PrimitiveValue :: Str ( s) => super :: deserialize:: parse_date ( s. trim_end ( ) . as_bytes ( ) )
2107
+ PrimitiveValue :: Str ( s) => super :: deserialize:: parse_date ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
2108
2108
. map ( |date| vec ! [ date] )
2109
2109
. context ( ParseDateSnafu )
2110
2110
. map_err ( |err| ConvertValueError {
@@ -2114,7 +2114,7 @@ impl PrimitiveValue {
2114
2114
} ) ,
2115
2115
PrimitiveValue :: Strs ( s) => s
2116
2116
. into_iter ( )
2117
- . map ( |s| super :: deserialize:: parse_date ( s. trim_end ( ) . as_bytes ( ) ) )
2117
+ . map ( |s| super :: deserialize:: parse_date ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) ) )
2118
2118
. collect :: < Result < Vec < _ > , _ > > ( )
2119
2119
. context ( ParseDateSnafu )
2120
2120
. map_err ( |err| ConvertValueError {
@@ -2262,7 +2262,7 @@ impl PrimitiveValue {
2262
2262
match self {
2263
2263
PrimitiveValue :: Date ( d) => Ok ( d. to_vec ( ) ) ,
2264
2264
PrimitiveValue :: Str ( s) => {
2265
- super :: deserialize:: parse_date_partial ( s. trim_end ( ) . as_bytes ( ) )
2265
+ super :: deserialize:: parse_date_partial ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
2266
2266
. map ( |( date, _) | vec ! [ date] )
2267
2267
. context ( ParseDateSnafu )
2268
2268
. map_err ( |err| ConvertValueError {
@@ -2274,7 +2274,7 @@ impl PrimitiveValue {
2274
2274
PrimitiveValue :: Strs ( s) => s
2275
2275
. into_iter ( )
2276
2276
. map ( |s| {
2277
- super :: deserialize:: parse_date_partial ( s. trim_end ( ) . as_bytes ( ) )
2277
+ super :: deserialize:: parse_date_partial ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
2278
2278
. map ( |( date, _rest) | date)
2279
2279
} )
2280
2280
. collect :: < Result < Vec < _ > , _ > > ( )
@@ -2353,7 +2353,7 @@ impl PrimitiveValue {
2353
2353
original : self . value_type ( ) ,
2354
2354
cause : Some ( Box :: from ( err) ) ,
2355
2355
} ) ,
2356
- PrimitiveValue :: Str ( s) => super :: deserialize:: parse_time ( s. trim_end ( ) . as_bytes ( ) )
2356
+ PrimitiveValue :: Str ( s) => super :: deserialize:: parse_time ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
2357
2357
. map ( |( date, _rest) | date)
2358
2358
. context ( ParseTimeSnafu )
2359
2359
. map_err ( |err| ConvertValueError {
@@ -2362,7 +2362,7 @@ impl PrimitiveValue {
2362
2362
cause : Some ( Box :: from ( err) ) ,
2363
2363
} ) ,
2364
2364
PrimitiveValue :: Strs ( s) => super :: deserialize:: parse_time (
2365
- s. first ( ) . map ( |s| s. trim_end ( ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
2365
+ s. first ( ) . map ( |s| s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
2366
2366
)
2367
2367
. map ( |( date, _rest) | date)
2368
2368
. context ( ParseTimeSnafu )
@@ -2450,7 +2450,7 @@ impl PrimitiveValue {
2450
2450
original : self . value_type ( ) ,
2451
2451
cause : Some ( Box :: from ( err) ) ,
2452
2452
} ) ,
2453
- PrimitiveValue :: Str ( s) => super :: deserialize:: parse_time ( s. trim_end ( ) . as_bytes ( ) )
2453
+ PrimitiveValue :: Str ( s) => super :: deserialize:: parse_time ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
2454
2454
. map ( |( date, _rest) | vec ! [ date] )
2455
2455
. context ( ParseDateSnafu )
2456
2456
. map_err ( |err| ConvertValueError {
@@ -2461,7 +2461,7 @@ impl PrimitiveValue {
2461
2461
PrimitiveValue :: Strs ( s) => s
2462
2462
. into_iter ( )
2463
2463
. map ( |s| {
2464
- super :: deserialize:: parse_time ( s. trim_end ( ) . as_bytes ( ) )
2464
+ super :: deserialize:: parse_time ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
2465
2465
. map ( |( date, _rest) | date)
2466
2466
} )
2467
2467
. collect :: < Result < Vec < _ > , _ > > ( )
@@ -2566,7 +2566,7 @@ impl PrimitiveValue {
2566
2566
match self {
2567
2567
PrimitiveValue :: Time ( t) if !t. is_empty ( ) => Ok ( t[ 0 ] ) ,
2568
2568
PrimitiveValue :: Str ( s) => {
2569
- super :: deserialize:: parse_time_partial ( s. trim_end ( ) . as_bytes ( ) )
2569
+ super :: deserialize:: parse_time_partial ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
2570
2570
. map ( |( date, _rest) | date)
2571
2571
. context ( ParseTimeSnafu )
2572
2572
. map_err ( |err| ConvertValueError {
@@ -2576,7 +2576,7 @@ impl PrimitiveValue {
2576
2576
} )
2577
2577
}
2578
2578
PrimitiveValue :: Strs ( s) => super :: deserialize:: parse_time_partial (
2579
- s. first ( ) . map ( |s| s. trim_end ( ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
2579
+ s. first ( ) . map ( |s| s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
2580
2580
)
2581
2581
. map ( |( date, _rest) | date)
2582
2582
. context ( ParseTimeSnafu )
@@ -2646,7 +2646,7 @@ impl PrimitiveValue {
2646
2646
match self {
2647
2647
PrimitiveValue :: Time ( t) => Ok ( t. to_vec ( ) ) ,
2648
2648
PrimitiveValue :: Str ( s) => {
2649
- super :: deserialize:: parse_time_partial ( s. trim_end ( ) . as_bytes ( ) )
2649
+ super :: deserialize:: parse_time_partial ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
2650
2650
. map ( |( date, _rest) | vec ! [ date] )
2651
2651
. context ( ParseDateSnafu )
2652
2652
. map_err ( |err| ConvertValueError {
@@ -2658,7 +2658,7 @@ impl PrimitiveValue {
2658
2658
PrimitiveValue :: Strs ( s) => s
2659
2659
. into_iter ( )
2660
2660
. map ( |s| {
2661
- super :: deserialize:: parse_time_partial ( s. trim_end ( ) . as_bytes ( ) )
2661
+ super :: deserialize:: parse_time_partial ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
2662
2662
. map ( |( date, _rest) | date)
2663
2663
} )
2664
2664
. collect :: < Result < Vec < _ > , _ > > ( )
@@ -2772,7 +2772,7 @@ impl PrimitiveValue {
2772
2772
match self {
2773
2773
PrimitiveValue :: DateTime ( v) if !v. is_empty ( ) => Ok ( v[ 0 ] ) ,
2774
2774
PrimitiveValue :: Str ( s) => {
2775
- super :: deserialize:: parse_datetime_partial ( s. trim_end ( ) . as_bytes ( ) )
2775
+ super :: deserialize:: parse_datetime_partial ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
2776
2776
. context ( ParseDateTimeSnafu )
2777
2777
. map_err ( |err| ConvertValueError {
2778
2778
requested : "DicomDateTime" ,
@@ -2781,7 +2781,7 @@ impl PrimitiveValue {
2781
2781
} )
2782
2782
}
2783
2783
PrimitiveValue :: Strs ( s) => super :: deserialize:: parse_datetime_partial (
2784
- s. first ( ) . map ( |s| s. trim_end ( ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
2784
+ s. first ( ) . map ( |s| s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
2785
2785
)
2786
2786
. context ( ParseDateTimeSnafu )
2787
2787
. map_err ( |err| ConvertValueError {
@@ -2812,7 +2812,7 @@ impl PrimitiveValue {
2812
2812
match self {
2813
2813
PrimitiveValue :: DateTime ( v) => Ok ( v. to_vec ( ) ) ,
2814
2814
PrimitiveValue :: Str ( s) => {
2815
- super :: deserialize:: parse_datetime_partial ( s. trim_end ( ) . as_bytes ( ) )
2815
+ super :: deserialize:: parse_datetime_partial ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
2816
2816
. map ( |date| vec ! [ date] )
2817
2817
. context ( ParseDateSnafu )
2818
2818
. map_err ( |err| ConvertValueError {
@@ -2823,7 +2823,7 @@ impl PrimitiveValue {
2823
2823
}
2824
2824
PrimitiveValue :: Strs ( s) => s
2825
2825
. into_iter ( )
2826
- . map ( |s| super :: deserialize:: parse_datetime_partial ( s. trim_end ( ) . as_bytes ( ) ) )
2826
+ . map ( |s| super :: deserialize:: parse_datetime_partial ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) ) )
2827
2827
. collect :: < Result < Vec < _ > , _ > > ( )
2828
2828
. context ( ParseDateSnafu )
2829
2829
. map_err ( |err| ConvertValueError {
@@ -2895,15 +2895,15 @@ impl PrimitiveValue {
2895
2895
original : self . value_type ( ) ,
2896
2896
cause : Some ( Box :: from ( err) ) ,
2897
2897
} ) ,
2898
- PrimitiveValue :: Str ( s) => super :: range:: parse_date_range ( s. trim_end ( ) . as_bytes ( ) )
2898
+ PrimitiveValue :: Str ( s) => super :: range:: parse_date_range ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
2899
2899
. context ( ParseDateRangeSnafu )
2900
2900
. map_err ( |err| ConvertValueError {
2901
2901
requested : "DateRange" ,
2902
2902
original : self . value_type ( ) ,
2903
2903
cause : Some ( Box :: from ( err) ) ,
2904
2904
} ) ,
2905
2905
PrimitiveValue :: Strs ( s) => super :: range:: parse_date_range (
2906
- s. first ( ) . map ( |s| s. trim_end ( ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
2906
+ s. first ( ) . map ( |s| s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
2907
2907
)
2908
2908
. context ( ParseDateRangeSnafu )
2909
2909
. map_err ( |err| ConvertValueError {
@@ -2978,15 +2978,15 @@ impl PrimitiveValue {
2978
2978
original : self . value_type ( ) ,
2979
2979
cause : Some ( Box :: from ( err) ) ,
2980
2980
} ) ,
2981
- PrimitiveValue :: Str ( s) => super :: range:: parse_time_range ( s. trim_end ( ) . as_bytes ( ) )
2981
+ PrimitiveValue :: Str ( s) => super :: range:: parse_time_range ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
2982
2982
. context ( ParseTimeRangeSnafu )
2983
2983
. map_err ( |err| ConvertValueError {
2984
2984
requested : "TimeRange" ,
2985
2985
original : self . value_type ( ) ,
2986
2986
cause : Some ( Box :: from ( err) ) ,
2987
2987
} ) ,
2988
2988
PrimitiveValue :: Strs ( s) => super :: range:: parse_time_range (
2989
- s. first ( ) . map ( |s| s. trim_end ( ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
2989
+ s. first ( ) . map ( |s| s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
2990
2990
)
2991
2991
. context ( ParseTimeRangeSnafu )
2992
2992
. map_err ( |err| ConvertValueError {
@@ -3092,15 +3092,15 @@ impl PrimitiveValue {
3092
3092
original : self . value_type ( ) ,
3093
3093
cause : Some ( Box :: from ( err) ) ,
3094
3094
} ) ,
3095
- PrimitiveValue :: Str ( s) => super :: range:: parse_datetime_range ( s. trim_end ( ) . as_bytes ( ) )
3095
+ PrimitiveValue :: Str ( s) => super :: range:: parse_datetime_range ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
3096
3096
. context ( ParseDateTimeRangeSnafu )
3097
3097
. map_err ( |err| ConvertValueError {
3098
3098
requested : "DateTimeRange" ,
3099
3099
original : self . value_type ( ) ,
3100
3100
cause : Some ( Box :: from ( err) ) ,
3101
3101
} ) ,
3102
3102
PrimitiveValue :: Strs ( s) => super :: range:: parse_datetime_range (
3103
- s. first ( ) . map ( |s| s. trim_end ( ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
3103
+ s. first ( ) . map ( |s| s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
3104
3104
)
3105
3105
. context ( ParseDateTimeRangeSnafu )
3106
3106
. map_err ( |err| ConvertValueError {
@@ -3197,7 +3197,7 @@ impl PrimitiveValue {
3197
3197
cause : Some ( Box :: from ( err) ) ,
3198
3198
} ) ,
3199
3199
PrimitiveValue :: Str ( s) => {
3200
- super :: range:: parse_datetime_range_custom :: < T > ( s. trim_end ( ) . as_bytes ( ) )
3200
+ super :: range:: parse_datetime_range_custom :: < T > ( s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) )
3201
3201
. context ( ParseDateTimeRangeSnafu )
3202
3202
. map_err ( |err| ConvertValueError {
3203
3203
requested : "DateTimeRange" ,
@@ -3206,7 +3206,7 @@ impl PrimitiveValue {
3206
3206
} )
3207
3207
}
3208
3208
PrimitiveValue :: Strs ( s) => super :: range:: parse_datetime_range_custom :: < T > (
3209
- s. first ( ) . map ( |s| s. trim_end ( ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
3209
+ s. first ( ) . map ( |s| s. trim_end_matches ( whitespace_or_null ) . as_bytes ( ) ) . unwrap_or ( & [ ] ) ,
3210
3210
)
3211
3211
. context ( ParseDateTimeRangeSnafu )
3212
3212
. map_err ( |err| ConvertValueError {
@@ -4349,6 +4349,11 @@ fn trim_last_whitespace(x: &[u8]) -> &[u8] {
4349
4349
}
4350
4350
}
4351
4351
4352
+ #[ inline]
4353
+ fn whitespace_or_null ( c : char ) -> bool {
4354
+ c. is_whitespace ( ) || c == '\0'
4355
+ }
4356
+
4352
4357
#[ cfg( test) ]
4353
4358
mod tests {
4354
4359
use super :: { CastValueError , ConvertValueError , InvalidValueReadError } ;
0 commit comments