3
3
//! This protocol is used in the boot services environment to perform
4
4
//! lexical comparison functions on Unicode strings for given languages.
5
5
6
- use crate :: data_types:: { CStr16 , CStr8 , Char16 , Char8 } ;
6
+ use crate :: data_types:: { CStr16 , CStr8 } ;
7
7
use crate :: proto:: unsafe_protocol;
8
8
use core:: cmp:: Ordering ;
9
9
use core:: fmt:: { self , Display , Formatter } ;
10
+ use uefi_raw:: protocol:: string:: UnicodeCollationProtocol ;
10
11
11
12
/// The Unicode Collation Protocol.
12
13
///
13
14
/// Used to perform case-insensitive comparisons of strings.
14
15
#[ derive( Debug ) ]
15
- #[ repr( C ) ]
16
- #[ unsafe_protocol( "a4c751fc-23ae-4c3e-92e9-4964cf63f349" ) ]
17
- pub struct UnicodeCollation {
18
- stri_coll : extern "efiapi" fn ( this : & Self , s1 : * const Char16 , s2 : * const Char16 ) -> isize ,
19
- metai_match :
20
- extern "efiapi" fn ( this : & Self , string : * const Char16 , pattern : * const Char16 ) -> bool ,
21
- str_lwr : extern "efiapi" fn ( this : & Self , s : * mut Char16 ) ,
22
- str_upr : extern "efiapi" fn ( this : & Self , s : * mut Char16 ) ,
23
- fat_to_str : extern "efiapi" fn ( this : & Self , fat_size : usize , fat : * const Char8 , s : * mut Char16 ) ,
24
- str_to_fat :
25
- extern "efiapi" fn ( this : & Self , s : * const Char16 , fat_size : usize , fat : * mut Char8 ) -> bool ,
26
- }
16
+ #[ repr( transparent) ]
17
+ #[ unsafe_protocol( UnicodeCollationProtocol :: GUID ) ]
18
+ pub struct UnicodeCollation ( UnicodeCollationProtocol ) ;
27
19
28
20
impl UnicodeCollation {
29
21
/// Performs a case insensitive comparison of two
30
22
/// null-terminated strings.
31
23
#[ must_use]
32
24
pub fn stri_coll ( & self , s1 : & CStr16 , s2 : & CStr16 ) -> Ordering {
33
- let order = ( self . stri_coll ) ( self , s1. as_ptr ( ) , s2. as_ptr ( ) ) ;
25
+ let order = unsafe { ( self . 0 . stri_coll ) ( & self . 0 , s1. as_ptr ( ) . cast ( ) , s2. as_ptr ( ) . cast ( ) ) } ;
34
26
order. cmp ( & 0 )
35
27
}
36
28
@@ -58,7 +50,7 @@ impl UnicodeCollation {
58
50
/// any single character followed by a "." followed by any string.
59
51
#[ must_use]
60
52
pub fn metai_match ( & self , s : & CStr16 , pattern : & CStr16 ) -> bool {
61
- ( self . metai_match ) ( self , s. as_ptr ( ) , pattern. as_ptr ( ) )
53
+ unsafe { ( self . 0 . metai_match ) ( & self . 0 , s. as_ptr ( ) . cast ( ) , pattern. as_ptr ( ) . cast ( ) ) }
62
54
}
63
55
64
56
/// Converts the characters in `s` to lower case characters.
@@ -75,7 +67,7 @@ impl UnicodeCollation {
75
67
* buf. get_mut ( last_index + 1 )
76
68
. ok_or ( StrConversionError :: BufferTooSmall ) ? = 0 ;
77
69
78
- ( self . str_lwr ) ( self , buf. as_ptr ( ) as * mut _ ) ;
70
+ unsafe { ( self . 0 . str_lwr ) ( & self . 0 , buf. as_mut_ptr ( ) ) } ;
79
71
80
72
Ok ( unsafe { CStr16 :: from_u16_with_nul_unchecked ( buf) } )
81
73
}
@@ -94,7 +86,7 @@ impl UnicodeCollation {
94
86
* buf. get_mut ( last_index + 1 )
95
87
. ok_or ( StrConversionError :: BufferTooSmall ) ? = 0 ;
96
88
97
- ( self . str_upr ) ( self , buf. as_ptr ( ) as * mut _ ) ;
89
+ unsafe { ( self . 0 . str_upr ) ( & self . 0 , buf. as_mut_ptr ( ) ) } ;
98
90
99
91
Ok ( unsafe { CStr16 :: from_u16_with_nul_unchecked ( buf) } )
100
92
}
@@ -108,12 +100,14 @@ impl UnicodeCollation {
108
100
if buf. len ( ) < fat. as_bytes ( ) . len ( ) {
109
101
return Err ( StrConversionError :: BufferTooSmall ) ;
110
102
}
111
- ( self . fat_to_str ) (
112
- self ,
113
- fat. as_bytes ( ) . len ( ) ,
114
- fat. as_ptr ( ) ,
115
- buf. as_ptr ( ) as * mut _ ,
116
- ) ;
103
+ unsafe {
104
+ ( self . 0 . fat_to_str ) (
105
+ & self . 0 ,
106
+ fat. as_bytes ( ) . len ( ) ,
107
+ fat. as_ptr ( ) . cast ( ) ,
108
+ buf. as_mut_ptr ( ) ,
109
+ )
110
+ } ;
117
111
Ok ( unsafe { CStr16 :: from_u16_with_nul_unchecked ( buf) } )
118
112
}
119
113
@@ -126,12 +120,14 @@ impl UnicodeCollation {
126
120
if s. as_slice_with_nul ( ) . len ( ) > buf. len ( ) {
127
121
return Err ( StrConversionError :: BufferTooSmall ) ;
128
122
}
129
- let failed = ( self . str_to_fat ) (
130
- self ,
131
- s. as_ptr ( ) ,
132
- s. as_slice_with_nul ( ) . len ( ) ,
133
- buf. as_ptr ( ) as * mut _ ,
134
- ) ;
123
+ let failed = unsafe {
124
+ ( self . 0 . str_to_fat ) (
125
+ & self . 0 ,
126
+ s. as_ptr ( ) . cast ( ) ,
127
+ s. as_slice_with_nul ( ) . len ( ) ,
128
+ buf. as_mut_ptr ( ) ,
129
+ )
130
+ } ;
135
131
if failed {
136
132
Err ( StrConversionError :: ConversionFailed )
137
133
} else {
0 commit comments