Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 65d6824

Browse files
author
Chris Yang
committed
revert format code
1 parent f2511d8 commit 65d6824

File tree

3 files changed

+15
-29
lines changed

3 files changed

+15
-29
lines changed

shell/platform/darwin/ios/framework/Source/FlutterSpellCheckPlugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
+ (instancetype)new NS_UNAVAILABLE;
2626
- (instancetype)initWithMisspelledRange:(NSRange)range
2727
suggestions:(NSArray<NSString*>*)suggestions NS_DESIGNATED_INITIALIZER;
28-
- (NSString*)toFormattedString;
28+
- (NSDictionary<NSString*, NSObject*>*)toDictionary;
2929

3030
@end
3131

shell/platform/darwin/ios/framework/Source/FlutterSpellCheckPlugin.mm

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
4949
// Get all the misspelled words and suggestions in the entire String.
5050
//
5151
// The result will be formatted as an NSArray.
52-
// Each item of the array is a JSON string representing a misspelled word and suggestions.
53-
// The JSON format looks like:
52+
// Each item of the array is a dictionary representing a misspelled word and suggestions.
53+
// The format looks like:
5454
// {
5555
// startIndex: 0,
5656
// endIndex: 5,
@@ -83,7 +83,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
8383
NSMutableArray* methodChannelResult = [[[NSMutableArray alloc] init] autorelease];
8484

8585
for (FlutterSpellCheckResult* result in allSpellSuggestions) {
86-
[methodChannelResult addObject:[result toFormattedString]];
86+
[methodChannelResult addObject:[result toDictionary]];
8787
}
8888

8989
[allSpellSuggestions release];
@@ -142,18 +142,12 @@ - (instancetype)initWithMisspelledRange:(NSRange)range
142142
return self;
143143
}
144144

145-
- (NSString*)toFormattedString {
146-
NSDictionary* map = @{
147-
@"startIndex" : @(_misspelledRange.location),
148-
@"endIndex" : @(_misspelledRange.location + _misspelledRange.length - 1),
149-
@"suggestions" : _suggestions,
150-
};
151-
152-
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:map options:kNilOptions error:nil];
153-
FML_DCHECK(jsonData != nil);
154-
NSString* jsonString = [[[NSString alloc] initWithData:jsonData
155-
encoding:NSUTF8StringEncoding] autorelease];
156-
return jsonString;
145+
- (NSDictionary<NSString*, NSObject*>*)toDictionary {
146+
NSMutableDictionary* result = [[[NSMutableDictionary alloc] initWithCapacity:3] autorelease];
147+
result[@"startIndex"] = @(_misspelledRange.location);
148+
result[@"endIndex"] = @(_misspelledRange.location + _misspelledRange.length - 1);
149+
result[@"suggestions"] = _suggestions;
150+
return result;
157151
}
158152

159153
- (void)dealloc {

shell/platform/darwin/ios/framework/Source/FlutterSpellCheckPluginTest.mm

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ - (void)testFindAllSpellCheckSuggestionsForText {
159159
capturedResult = result;
160160
}];
161161
XCTAssertTrue(capturedResult.count == 2);
162-
NSDictionary* suggestionsJSON1 = [self decodeJson:capturedResult.firstObject];
162+
NSDictionary* suggestionsJSON1 = capturedResult.firstObject;
163163
XCTAssertEqualObjects(suggestionsJSON1[@"startIndex"], @0);
164164
XCTAssertEqualObjects(suggestionsJSON1[@"endIndex"], @4);
165165
XCTAssertEqualObjects(suggestionsJSON1[@"suggestions"], suggestions1);
166-
NSDictionary* suggestionsJSON2 = [self decodeJson:capturedResult[1]];
166+
NSDictionary* suggestionsJSON2 = capturedResult[1];
167167
XCTAssertEqualObjects(suggestionsJSON2[@"startIndex"], @5);
168168
XCTAssertEqualObjects(suggestionsJSON2[@"endIndex"], @9);
169169
XCTAssertEqualObjects(suggestionsJSON2[@"suggestions"], suggestions2);
@@ -196,11 +196,11 @@ - (void)testStopFindingMoreWhenTheLastWordIsMisspelled {
196196
capturedResult = result;
197197
}];
198198
XCTAssertTrue(capturedResult.count == 2);
199-
NSDictionary* suggestionsJSON1 = [self decodeJson:capturedResult.firstObject];
199+
NSDictionary* suggestionsJSON1 = capturedResult.firstObject;
200200
XCTAssertEqualObjects(suggestionsJSON1[@"startIndex"], @0);
201201
XCTAssertEqualObjects(suggestionsJSON1[@"endIndex"], @4);
202202
XCTAssertEqualObjects(suggestionsJSON1[@"suggestions"], suggestions1);
203-
NSDictionary* suggestionsJSON2 = [self decodeJson:capturedResult[1]];
203+
NSDictionary* suggestionsJSON2 = capturedResult[1];
204204
XCTAssertEqualObjects(suggestionsJSON2[@"startIndex"], @6);
205205
XCTAssertEqualObjects(suggestionsJSON2[@"endIndex"], @9);
206206
XCTAssertEqualObjects(suggestionsJSON2[@"suggestions"], suggestions2);
@@ -226,7 +226,7 @@ - (void)testStopFindingMoreWhenTheWholeStringIsAMisspelledWord {
226226
capturedResult = result;
227227
}];
228228
XCTAssertTrue(capturedResult.count == 1);
229-
NSDictionary* suggestionsJSON1 = [self decodeJson:capturedResult.firstObject];
229+
NSDictionary* suggestionsJSON1 = capturedResult.firstObject;
230230
XCTAssertEqualObjects(suggestionsJSON1[@"startIndex"], @0);
231231
XCTAssertEqualObjects(suggestionsJSON1[@"endIndex"], @4);
232232
XCTAssertEqualObjects(suggestionsJSON1[@"suggestions"], suggestions1);
@@ -338,12 +338,4 @@ - (void)mockUITextCheckerWithExpectedMisspelledWordRange:(NSRange)expectedRange
338338
withStartingIndex:startingIndex];
339339
}
340340

341-
- (NSDictionary*)decodeJson:(NSString*)jsonString {
342-
NSData* data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
343-
NSDictionary* dictionary = [NSJSONSerialization JSONObjectWithData:data
344-
options:kNilOptions
345-
error:nil];
346-
return dictionary;
347-
}
348-
349341
@end

0 commit comments

Comments
 (0)