Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

amp parsing fixed

  • Loading branch information...
commit 310e0a6995d6e6b8dab35fc1d2d803efc50fb635 1 parent b398b4c
@parisman parisman authored
View
7 Classes/ElementParser.m
@@ -217,7 +217,12 @@ -(BOOL)shouldBeEmptyElement:(Element*)element{
}
-(id)buildElementTreeWithChunk:(Chunk*)chunk context:(void*)builder{
-// NSLog([chunk description]);
+/*
+ used to hunt down problem strings in example documents
+ BOOL breakpoint = [[chunk description] rangeOfString: @""].location != NSNotFound;
+ if (breakpoint)
+ NSLog(@"found breakpoint");
+*/
self.lastChunk = chunk;
if (![chunk isKind: ChunkKindText])
lastOpened.containsMarkup = YES;
View
4 Classes/NSString_HTML.h
@@ -67,8 +67,8 @@ CFIndex lenToken(CFStringInlineBuffer* buffer, CFIndex index);
CFIndex startsWithStr(CFStringInlineBuffer* buffer, CFIndex index, const char* prefix);
/**
- * Parses an entity name and returns its length. Returns 0 if end of buffer or
- * an invalid entity is encountered.
+ * Parses an entity name and returns its length. Returns 0 if end of buffer
+ * is encountered or NSNotFound of an invalid entity is encountered.
*/
CFIndex lenEntityName(CFStringInlineBuffer* buffer, CFIndex index);
View
17 Classes/NSString_HTML.m
@@ -107,7 +107,7 @@ CFIndex lenEntityName(CFStringInlineBuffer* buffer, CFIndex index){
if (c==';')
return len + 1;
if (((c < 'a') || (c > 'z')) && ((c < 'A') || (c > 'Z')) && ((c < '0') || (c > '9')) && (c != '#'))
- break;
+ return NSNotFound;
len++;
}
return 0;
@@ -458,12 +458,17 @@ +(void)parseHTML:(NSString*)source delegate:(id)delegate selector:(SEL)selector
partialChunk = tag;
}
else if (c == '&'){
- interior = lenEntityName(&buffer, index)-2;
- if (interior > 0){
+ // complicated by the fact that what appears to be an entity may infact just be text
+ CFIndex entityLen = lenEntityName(&buffer, index);
+ if (entityLen == NSNotFound){
+ len = lenThruOr(&buffer, index + 1, '<', '&') + 1;
+ chunk = text;
+ }
+ else if (entityLen > 0){
chunk = entity;
- len = interior + 2;
+ len = entityLen;
}
- else
+ else
partialChunk = entity;
}
else{
@@ -486,7 +491,7 @@ +(void)parseHTML:(NSString*)source delegate:(id)delegate selector:(SEL)selector
// hand the chunk to the delgate
chunk.range = NSMakeRange(index + buffer.rangeToBuffer.location, len);
-// NSLog([NSString stringWithFormat: @"%@: %@", [[chunk class] humanName], [source substringWithRange: chunk.range]]);
+// NSLog(@"%@: %@", [[chunk class] humanName], [source substringWithRange: chunk.range]);
chunk.buffer = &buffer;
delegateWantsToContinue = [delegate performSelector: selector withObject: chunk withObject: context] != nil;
index += len;
View
10 Demo/Classes/DemoViewController.m
@@ -31,12 +31,18 @@ - (void)loadView {
*/
-/*
+
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
+ /* pre populate source with the source.html file */
+ NSString* path = [[NSBundle mainBundle] pathForResource: @"source" ofType: @"html"];
+ NSStringEncoding encoding;
+ self.source = [NSString stringWithContentsOfFile: path usedEncoding: &encoding error: NULL];
+ textView.text = self.source;
+ self.pattern = @"*";
}
-*/
+
/*
View
4 Demo/Demo.xcodeproj/project.pbxproj
@@ -32,6 +32,7 @@
DC65743D1042E7C500BE3D62 /* TagChunk.m in Sources */ = {isa = PBXBuildFile; fileRef = DC65742A1042E7C500BE3D62 /* TagChunk.m */; };
DC65743E1042E7C500BE3D62 /* TxtChunk.m in Sources */ = {isa = PBXBuildFile; fileRef = DC65742C1042E7C500BE3D62 /* TxtChunk.m */; };
DC65743F1042E7C500BE3D62 /* URLParser.m in Sources */ = {isa = PBXBuildFile; fileRef = DC65742E1042E7C500BE3D62 /* URLParser.m */; };
+ DC903C0610777B8000F65535 /* source.html in Resources */ = {isa = PBXBuildFile; fileRef = DC903C0510777B8000F65535 /* source.html */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -82,6 +83,7 @@
DC65742C1042E7C500BE3D62 /* TxtChunk.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TxtChunk.m; path = ../Classes/TxtChunk.m; sourceTree = SOURCE_ROOT; };
DC65742D1042E7C500BE3D62 /* URLParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = URLParser.h; path = ../Classes/URLParser.h; sourceTree = SOURCE_ROOT; };
DC65742E1042E7C500BE3D62 /* URLParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = URLParser.m; path = ../Classes/URLParser.m; sourceTree = SOURCE_ROOT; };
+ DC903C0510777B8000F65535 /* source.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = source.html; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -143,6 +145,7 @@
isa = PBXGroup;
children = (
2899E5210DE3E06400AC0155 /* DemoViewController.xib */,
+ DC903C0510777B8000F65535 /* source.html */,
28AD733E0D9D9553002E5188 /* MainWindow.xib */,
8D1107310486CEB800E47090 /* Demo-Info.plist */,
);
@@ -245,6 +248,7 @@
files = (
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */,
2899E5220DE3E06400AC0155 /* DemoViewController.xib in Resources */,
+ DC903C0610777B8000F65535 /* source.html in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
725 Demo/source.html
725 additions, 0 deletions not shown
Please sign in to comment.
Something went wrong with that request. Please try again.