chore: modernize ListValue usage in dict_util.mm and related files (#34661)
* chore: modernize ListValue usage in dict_util.mm and related files * use base::Value::{Dict,List} instead of raw base::Value * fix compile * fix build * fix build again
This commit is contained in:
parent
cd19a741b1
commit
11924bdbb2
14 changed files with 106 additions and 107 deletions
|
@ -12,9 +12,9 @@
|
|||
|
||||
namespace electron {
|
||||
|
||||
NSArray* ListValueToNSArray(const base::ListValue& value) {
|
||||
NSArray* ListValueToNSArray(const base::Value::List& value) {
|
||||
std::string json;
|
||||
if (!base::JSONWriter::Write(value, &json))
|
||||
if (!base::JSONWriter::Write(base::Value(value.Clone()), &json))
|
||||
return nil;
|
||||
NSData* jsonData = [NSData dataWithBytes:json.c_str() length:json.length()];
|
||||
id obj = [NSJSONSerialization JSONObjectWithData:jsonData
|
||||
|
@ -25,8 +25,8 @@ NSArray* ListValueToNSArray(const base::ListValue& value) {
|
|||
return obj;
|
||||
}
|
||||
|
||||
base::ListValue NSArrayToListValue(NSArray* arr) {
|
||||
base::ListValue result;
|
||||
base::Value::List NSArrayToValue(NSArray* arr) {
|
||||
base::Value::List result;
|
||||
if (!arr)
|
||||
return result;
|
||||
|
||||
|
@ -44,9 +44,9 @@ base::ListValue NSArrayToListValue(NSArray* arr) {
|
|||
else
|
||||
result.Append([value intValue]);
|
||||
} else if ([value isKindOfClass:[NSArray class]]) {
|
||||
result.Append(NSArrayToListValue(value));
|
||||
result.Append(NSArrayToValue(value));
|
||||
} else if ([value isKindOfClass:[NSDictionary class]]) {
|
||||
result.Append(NSDictionaryToDictionaryValue(value));
|
||||
result.Append(NSDictionaryToValue(value));
|
||||
} else {
|
||||
result.Append(base::SysNSStringToUTF8([value description]));
|
||||
}
|
||||
|
@ -55,10 +55,9 @@ base::ListValue NSArrayToListValue(NSArray* arr) {
|
|||
return result;
|
||||
}
|
||||
|
||||
NSDictionary* DictionaryValueToNSDictionary(
|
||||
const base::DictionaryValue& value) {
|
||||
NSDictionary* DictionaryValueToNSDictionary(const base::Value::Dict& value) {
|
||||
std::string json;
|
||||
if (!base::JSONWriter::Write(value, &json))
|
||||
if (!base::JSONWriter::Write(base::Value(value.Clone()), &json))
|
||||
return nil;
|
||||
NSData* jsonData = [NSData dataWithBytes:json.c_str() length:json.length()];
|
||||
id obj = [NSJSONSerialization JSONObjectWithData:jsonData
|
||||
|
@ -69,8 +68,8 @@ NSDictionary* DictionaryValueToNSDictionary(
|
|||
return obj;
|
||||
}
|
||||
|
||||
base::DictionaryValue NSDictionaryToDictionaryValue(NSDictionary* dict) {
|
||||
base::DictionaryValue result;
|
||||
base::Value::Dict NSDictionaryToValue(NSDictionary* dict) {
|
||||
base::Value::Dict result;
|
||||
if (!dict)
|
||||
return result;
|
||||
|
||||
|
@ -80,24 +79,24 @@ base::DictionaryValue NSDictionaryToDictionaryValue(NSDictionary* dict) {
|
|||
|
||||
id value = [dict objectForKey:key];
|
||||
if ([value isKindOfClass:[NSString class]]) {
|
||||
result.SetKey(str_key, base::Value(base::SysNSStringToUTF8(value)));
|
||||
result.Set(str_key, base::Value(base::SysNSStringToUTF8(value)));
|
||||
} else if ([value isKindOfClass:[NSNumber class]]) {
|
||||
const char* objc_type = [value objCType];
|
||||
if (strcmp(objc_type, @encode(BOOL)) == 0 ||
|
||||
strcmp(objc_type, @encode(char)) == 0)
|
||||
result.SetKey(str_key, base::Value([value boolValue]));
|
||||
result.Set(str_key, base::Value([value boolValue]));
|
||||
else if (strcmp(objc_type, @encode(double)) == 0 ||
|
||||
strcmp(objc_type, @encode(float)) == 0)
|
||||
result.SetKey(str_key, base::Value([value doubleValue]));
|
||||
result.Set(str_key, base::Value([value doubleValue]));
|
||||
else
|
||||
result.SetKey(str_key, base::Value([value intValue]));
|
||||
result.Set(str_key, base::Value([value intValue]));
|
||||
} else if ([value isKindOfClass:[NSArray class]]) {
|
||||
result.SetKey(str_key, NSArrayToListValue(value));
|
||||
result.Set(str_key, NSArrayToValue(value));
|
||||
} else if ([value isKindOfClass:[NSDictionary class]]) {
|
||||
result.SetKey(str_key, NSDictionaryToDictionaryValue(value));
|
||||
result.Set(str_key, NSDictionaryToValue(value));
|
||||
} else {
|
||||
result.SetKey(str_key,
|
||||
base::Value(base::SysNSStringToUTF8([value description])));
|
||||
result.Set(str_key,
|
||||
base::Value(base::SysNSStringToUTF8([value description])));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue