@@ -1152,15 +1152,17 @@ pub unsafe extern "C" fn pdf_set_string(
11521152 } ;
11531153}
11541154/* Name does *not* include the /. */
1155- pub unsafe fn pdf_new_name ( name : & str ) -> * mut pdf_obj {
1155+ pub unsafe fn pdf_new_name < K > ( name : K ) -> * mut pdf_obj
1156+ where
1157+ K : Into < Vec < u8 > > ,
1158+ {
11561159 let mut result: * mut pdf_obj = 0 as * mut pdf_obj ;
11571160 let mut data: * mut pdf_name = 0 as * mut pdf_name ;
11581161 result = pdf_new_obj ( PdfObjType :: NAME ) ;
11591162 data = new ( :: std:: mem:: size_of :: < pdf_name > ( ) as u32 ) as * mut pdf_name ;
11601163 ( * result) . data = data as * mut libc:: c_void ;
1161- let length = name. len ( ) ;
11621164 let name = CString :: new ( name) . unwrap ( ) ;
1163- if length != 0 {
1165+ if name . to_bytes ( ) . len ( ) != 0 {
11641166 ( * data) . name = name. into_raw ( ) ;
11651167 } else {
11661168 ( * data) . name = 0 as * mut i8
@@ -1447,12 +1449,10 @@ unsafe extern "C" fn release_dict(mut data: *mut pdf_dict) {
14471449}
14481450/* Array is ended by a node with NULL this pointer */
14491451/* pdf_add_dict returns 0 if the key is new and non-zero otherwise */
1450- #[ no_mangle]
1451- pub unsafe extern "C" fn pdf_add_dict (
1452- mut dict : * mut pdf_obj ,
1453- key : & str ,
1454- mut value : * mut pdf_obj ,
1455- ) -> i32 {
1452+ pub unsafe fn pdf_add_dict < K > ( mut dict : * mut pdf_obj , key : K , mut value : * mut pdf_obj ) -> i32
1453+ where
1454+ K : Into < Vec < u8 > > + AsRef < [ u8 ] > ,
1455+ {
14561456 let mut data: * mut pdf_dict = 0 as * mut pdf_dict ;
14571457 let mut new_node: * mut pdf_dict = 0 as * mut pdf_dict ;
14581458 if dict. is_null ( ) || !( * dict) . is_dict ( ) {
@@ -1470,7 +1470,7 @@ pub unsafe extern "C" fn pdf_add_dict(
14701470 /* If this key already exists, simply replace the value */
14711471 data = ( * dict) . data as * mut pdf_dict ;
14721472 while !( * data) . key . is_null ( ) {
1473- if key == pdf_name_value ( & * ( * data) . key ) . to_string_lossy ( ) {
1473+ if key. as_ref ( ) == pdf_name_value ( & * ( * data) . key ) . to_bytes ( ) {
14741474 /* Release the old value */
14751475 pdf_release_obj ( ( * data) . value ) ;
14761476 ( * data) . value = value;
@@ -1526,7 +1526,7 @@ pub unsafe extern "C" fn pdf_merge_dict(mut dict1: *mut pdf_obj, mut dict2: *mut
15261526 pdf_add_dict (
15271527 dict1,
15281528 //pdf_link_obj((*data).key),
1529- pdf_name_value ( & * ( * data) . key ) . to_str ( ) . unwrap ( ) ,
1529+ pdf_name_value ( & * ( * data) . key ) . to_bytes ( ) ,
15301530 pdf_link_obj ( ( * data) . value ) ,
15311531 ) ;
15321532 data = ( * data) . next
@@ -1558,11 +1558,11 @@ pub unsafe extern "C" fn pdf_foreach_dict(
15581558 }
15591559 error
15601560}
1561- # [ no_mangle ]
1562- pub unsafe extern "C" fn pdf_lookup_dict (
1563- mut dict : * mut pdf_obj ,
1564- name : & str ,
1565- ) -> Option < * mut pdf_obj > {
1561+
1562+ pub unsafe fn pdf_lookup_dict < K > ( mut dict : * mut pdf_obj , name : K ) -> Option < * mut pdf_obj >
1563+ where
1564+ K : AsRef < [ u8 ] > ,
1565+ {
15661566 let mut data: * mut pdf_dict = 0 as * mut pdf_dict ;
15671567 if dict. is_null ( ) || !( * dict) . is_dict ( ) {
15681568 panic ! (
@@ -1574,7 +1574,7 @@ pub unsafe extern "C" fn pdf_lookup_dict(
15741574 }
15751575 data = ( * dict) . data as * mut pdf_dict ;
15761576 while !( * data) . key . is_null ( ) {
1577- if name == pdf_name_value ( & * ( * data) . key ) . to_string_lossy ( ) {
1577+ if name. as_ref ( ) == pdf_name_value ( & * ( * data) . key ) . to_bytes ( ) {
15781578 return Some ( ( * data) . value ) ;
15791579 }
15801580 data = ( * data) . next
@@ -1605,8 +1605,11 @@ pub unsafe extern "C" fn pdf_dict_keys(mut dict: *mut pdf_obj) -> *mut pdf_obj {
16051605 }
16061606 keys
16071607}
1608- #[ no_mangle]
1609- pub unsafe extern "C" fn pdf_remove_dict ( mut dict : * mut pdf_obj , name : & str ) {
1608+
1609+ pub unsafe fn pdf_remove_dict < K > ( mut dict : * mut pdf_obj , name : K )
1610+ where
1611+ K : AsRef < [ u8 ] > ,
1612+ {
16101613 let mut data: * mut pdf_dict = 0 as * mut pdf_dict ;
16111614 let mut data_p: * mut * mut pdf_dict = 0 as * mut * mut pdf_dict ;
16121615 if dict. is_null ( ) || !( * dict) . is_dict ( ) {
@@ -1621,8 +1624,8 @@ pub unsafe extern "C" fn pdf_remove_dict(mut dict: *mut pdf_obj, name: &str) {
16211624 data_p = & mut ( * dict) . data as * mut * mut libc:: c_void as * mut libc:: c_void as * mut * mut pdf_dict ;
16221625 while !( * data) . key . is_null ( ) {
16231626 if !( * data) . key . is_null ( )
1624- && ( CStr :: from_ptr ( ( * ( ( * ( * data) . key ) . data as * mut pdf_name ) ) . name ) . to_string_lossy ( )
1625- == name)
1627+ && ( CStr :: from_ptr ( ( * ( ( * ( * data) . key ) . data as * mut pdf_name ) ) . name ) . to_bytes ( )
1628+ == name. as_ref ( ) )
16261629 {
16271630 pdf_release_obj ( ( * data) . key ) ;
16281631 pdf_release_obj ( ( * data) . value ) ;
@@ -4533,7 +4536,7 @@ unsafe extern "C" fn import_dict(
45334536 if tmp. is_null ( ) {
45344537 return -1i32 ;
45354538 }
4536- pdf_add_dict ( copy, pdf_name_value ( & * key) . to_str ( ) . unwrap ( ) , tmp) ; // TODO: check
4539+ pdf_add_dict ( copy, pdf_name_value ( & * key) . to_bytes ( ) , tmp) ; // TODO: check
45374540 0i32
45384541}
45394542static mut loop_marker: pdf_obj = {
0 commit comments