Skip to content

Commit 9d63191

Browse files
author
Neil Fraser
committed
Initial port from code.google.com
Plus header changes required by Google’s open source office.
0 parents  commit 9d63191

27 files changed

+6477
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "Base.xcconfig"
2+
3+
SDKROOT = macosx10.6
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "Version.xcconfig"
2+
3+
SDKROOT = macosx10.5
4+
PREBINDING = NO
5+
ARCHS = i386 x86_64
6+
//ARCHS = ppc i386 x86_64 // PPC works, but fails the timing tests under Rosetta
7+
8+
GCC_VERSION = com.apple.compilers.llvm.clang.1_0
9+
GCC_C_LANGUAGE_STANDARD = gnu99
10+
11+
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES
12+
GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO
13+
GCC_WARN_SHADOW = YES
14+
GCC_TREAT_WARNINGS_AS_ERRORS = YES
15+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES
16+
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES
17+
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES
18+
GCC_WARN_ABOUT_RETURN_TYPE = YES
19+
GCC_WARN_MISSING_PARENTHESES = YES
20+
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES
21+
GCC_WARN_ABOUT_MISSING_NEWLINE = YES
22+
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES
23+
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
24+
GCC_WARN_SIGN_COMPARE = YES
25+
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES
26+
GCC_WARN_UNDECLARED_SELECTOR = YES
27+
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES
28+
GCC_WARN_UNINITIALIZED_AUTOS = YES
29+
GCC_WARN_UNKNOWN_PRAGMAS = YES
30+
GCC_WARN_UNUSED_FUNCTION = YES
31+
GCC_WARN_UNUSED_LABEL = YES
32+
GCC_WARN_UNUSED_PARAMETER = NO
33+
GCC_WARN_UNUSED_VALUE = YES
34+
GCC_WARN_UNUSED_VARIABLE = YES
35+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MARKETING_VERSION = 1.0.3
2+
PROJECT_VERSION = 1000

objectivec/DiffMatchPatch.h

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* Diff Match and Patch
3+
* Copyright 2018 The diff-match-patch Authors.
4+
* https://github.com/google/diff-match-patch
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Author: fraser@google.com (Neil Fraser)
19+
* ObjC port: jan@geheimwerk.de (Jan Weiß)
20+
*/
21+
22+
#import <Foundation/Foundation.h>
23+
24+
/*
25+
* Functions for diff, match and patch.
26+
* Computes the difference between two texts to create a patch.
27+
* Applies the patch onto another text, allowing for errors.
28+
*/
29+
30+
/*
31+
* The data structure representing a diff is an NSMutableArray of Diff objects:
32+
* {Diff(Operation.DIFF_DELETE, "Hello"),
33+
* Diff(Operation.DIFF_INSERT, "Goodbye"),
34+
* Diff(Operation.DIFF_EQUAL, " world.")}
35+
* which means: delete "Hello", add "Goodbye" and keep " world."
36+
*/
37+
38+
typedef enum {
39+
DIFF_DELETE = 1,
40+
DIFF_INSERT = 2,
41+
DIFF_EQUAL = 3
42+
} Operation;
43+
44+
45+
/*
46+
* Class representing one diff operation.
47+
*/
48+
@interface Diff : NSObject <NSCopying> {
49+
Operation operation; // One of: DIFF_INSERT, DIFF_DELETE or DIFF_EQUAL.
50+
NSString *text; // The text associated with this diff operation.
51+
}
52+
53+
@property (nonatomic, assign) Operation operation;
54+
@property (nonatomic, copy) NSString *text;
55+
56+
+ (id)diffWithOperation:(Operation)anOperation andText:(NSString *)aText;
57+
58+
- (id)initWithOperation:(Operation)anOperation andText:(NSString *)aText;
59+
60+
@end
61+
62+
/*
63+
* Class representing one patch operation.
64+
*/
65+
@interface Patch : NSObject <NSCopying> {
66+
NSMutableArray *diffs;
67+
NSUInteger start1;
68+
NSUInteger start2;
69+
NSUInteger length1;
70+
NSUInteger length2;
71+
}
72+
73+
@property (nonatomic, retain) NSMutableArray *diffs;
74+
@property (nonatomic, assign) NSUInteger start1;
75+
@property (nonatomic, assign) NSUInteger start2;
76+
@property (nonatomic, assign) NSUInteger length1;
77+
@property (nonatomic, assign) NSUInteger length2;
78+
79+
@end
80+
81+
82+
/*
83+
* Class containing the diff, match and patch methods.
84+
* Also Contains the behaviour settings.
85+
*/
86+
@interface DiffMatchPatch : NSObject {
87+
// Number of seconds to map a diff before giving up (0 for infinity).
88+
NSTimeInterval Diff_Timeout;
89+
90+
// Cost of an empty edit operation in terms of edit characters.
91+
NSUInteger Diff_EditCost;
92+
93+
// At what point is no match declared (0.0 = perfection, 1.0 = very loose).
94+
double Match_Threshold;
95+
96+
// How far to search for a match (0 = exact location, 1000+ = broad match).
97+
// A match this many characters away from the expected location will add
98+
// 1.0 to the score (0.0 is a perfect match).
99+
NSInteger Match_Distance;
100+
101+
// When deleting a large block of text (over ~64 characters), how close
102+
// do the contents have to be to match the expected contents. (0.0 =
103+
// perfection, 1.0 = very loose). Note that Match_Threshold controls
104+
// how closely the end points of a delete need to match.
105+
float Patch_DeleteThreshold;
106+
107+
// Chunk size for context length.
108+
uint16_t Patch_Margin;
109+
110+
// The number of bits in an int.
111+
NSUInteger Match_MaxBits;
112+
}
113+
114+
@property (nonatomic, assign) NSTimeInterval Diff_Timeout;
115+
@property (nonatomic, assign) NSUInteger Diff_EditCost;
116+
@property (nonatomic, assign) double Match_Threshold;
117+
@property (nonatomic, assign) NSInteger Match_Distance;
118+
@property (nonatomic, assign) float Patch_DeleteThreshold;
119+
@property (nonatomic, assign) uint16_t Patch_Margin;
120+
121+
- (NSMutableArray *)diff_mainOfOldString:(NSString *)text1 andNewString:(NSString *)text2;
122+
- (NSMutableArray *)diff_mainOfOldString:(NSString *)text1 andNewString:(NSString *)text2 checkLines:(BOOL)checklines;
123+
- (NSUInteger)diff_commonPrefixOfFirstString:(NSString *)text1 andSecondString:(NSString *)text2;
124+
- (NSUInteger)diff_commonSuffixOfFirstString:(NSString *)text1 andSecondString:(NSString *)text2;
125+
- (void)diff_cleanupSemantic:(NSMutableArray *)diffs;
126+
- (void)diff_cleanupSemanticLossless:(NSMutableArray *)diffs;
127+
- (void)diff_cleanupEfficiency:(NSMutableArray *)diffs;
128+
- (void)diff_cleanupMerge:(NSMutableArray *)diffs;
129+
- (NSUInteger)diff_xIndexIn:(NSMutableArray *)diffs location:(NSUInteger) loc;
130+
- (NSString *)diff_prettyHtml:(NSMutableArray *)diffs;
131+
- (NSString *)diff_text1:(NSMutableArray *)diffs;
132+
- (NSString *)diff_text2:(NSMutableArray *)diffs;
133+
- (NSUInteger)diff_levenshtein:(NSMutableArray *)diffs;
134+
- (NSString *)diff_toDelta:(NSMutableArray *)diffs;
135+
- (NSMutableArray *)diff_fromDeltaWithText:(NSString *)text1 andDelta:(NSString *)delta error:(NSError **)error;
136+
137+
- (NSUInteger)match_mainForText:(NSString *)text pattern:(NSString *)pattern near:(NSUInteger)loc;
138+
- (NSMutableDictionary *)match_alphabet:(NSString *)pattern;
139+
140+
- (NSMutableArray *)patch_makeFromOldString:(NSString *)text1 andNewString:(NSString *)text2;
141+
- (NSMutableArray *)patch_makeFromDiffs:(NSMutableArray *)diffs;
142+
- (NSMutableArray *)patch_makeFromOldString:(NSString *)text1 newString:(NSString *)text2 diffs:(NSMutableArray *)diffs;
143+
- (NSMutableArray *)patch_makeFromOldString:(NSString *)text1 andDiffs:(NSMutableArray *)diffs;
144+
- (NSMutableArray *)patch_deepCopy:(NSArray *)patches; // Copy rule applies!
145+
- (NSArray *)patch_apply:(NSArray *)sourcePatches toString:(NSString *)text;
146+
- (NSString *)patch_addPadding:(NSMutableArray *)patches;
147+
- (void)patch_splitMax:(NSMutableArray *)patches;
148+
- (NSString *)patch_toText:(NSMutableArray *)patches;
149+
- (NSMutableArray *)patch_fromText:(NSString *)textline error:(NSError **)error;
150+
151+
@end
152+
153+
154+
@interface DiffMatchPatch (PrivateMethods)
155+
156+
- (NSMutableArray *)diff_mainOfOldString:(NSString *)text1 andNewString:(NSString *)text2 checkLines:(BOOL)checklines deadline:(NSTimeInterval)deadline;
157+
- (NSMutableArray *)diff_computeFromOldString:(NSString *)text1 andNewString:(NSString *)text2 checkLines:(BOOL)checklines deadline:(NSTimeInterval)deadline;
158+
- (NSMutableArray *)diff_lineModeFromOldString:(NSString *)text1 andNewString:(NSString *)text2 deadline:(NSTimeInterval)deadline;
159+
- (NSArray *)diff_linesToCharsForFirstString:(NSString *)text1 andSecondString:(NSString *)text1;
160+
- (NSString *)diff_linesToCharsMungeOfText:(NSString *)text lineArray:(NSMutableArray *)lineArray lineHash:(NSMutableDictionary *)lineHash;
161+
- (void)diff_chars:(NSArray *)diffs toLines:(NSMutableArray *)lineArray;
162+
- (NSMutableArray *)diff_bisectOfOldString:(NSString *)text1 andNewString:(NSString *)text2 deadline:(NSTimeInterval)deadline;
163+
- (NSMutableArray *)diff_bisectSplitOfOldString:(NSString *)text1 andNewString:(NSString *)text2 x:(NSUInteger)x y:(NSUInteger)y deadline:(NSTimeInterval)deadline;
164+
- (NSUInteger)diff_commonOverlapOfFirstString:(NSString *)text1 andSecondString:(NSString *)text2;
165+
- (NSArray *)diff_halfMatchOfFirstString:(NSString *)text1 andSecondString:(NSString *)text2;
166+
- (NSArray *)diff_halfMatchIOfLongString:(NSString *)longtext andShortString:(NSString *)shorttext;
167+
- (NSInteger)diff_cleanupSemanticScoreOfFirstString:(NSString *)one andSecondString:(NSString *)two;
168+
169+
- (NSUInteger)match_bitapOfText:(NSString *)text andPattern:(NSString *)pattern near:(NSUInteger)loc;
170+
- (double)match_bitapScoreForErrorCount:(NSUInteger)e location:(NSUInteger)x near:(NSUInteger)loc pattern:(NSString *)pattern;
171+
172+
- (void)patch_addContextToPatch:(Patch *)patch sourceText:(NSString *)text;
173+
174+
@end

0 commit comments

Comments
 (0)