forked from fedefrappi/AePubReader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Customized the uislider appereance, added html parsing to support ful…
…l-text search
- Loading branch information
1 parent
ebde807
commit 053187c
Showing
44 changed files
with
3,855 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// CDataChunk.h | ||
// Thumbprint | ||
// | ||
// Created by Lee Buck on 4/21/09. | ||
// Copyright 2009 Blue Bright Ventures. All rights reserved. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// Commercial licences without many of the obligations of GPL | ||
// are available for a nomial fee at [email protected]. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "Chunk.h" | ||
|
||
/** | ||
CDataChunk a chunk corresponding to a CDATA section | ||
*/ | ||
@interface CDataChunk : Chunk { | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// CDataChunk.m | ||
// Thumbprint | ||
// | ||
// Created by Lee Buck on 4/21/09. | ||
// Copyright 2009 Blue Bright Ventures. All rights reserved. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// Commercial licences without many of the obligations of GPL | ||
// are available for a nomial fee at [email protected]. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
#import "CDataChunk.h" | ||
|
||
|
||
@implementation CDataChunk | ||
|
||
-(NSString*)kind{ | ||
return ChunkKindCData; | ||
} | ||
|
||
-(NSRange)interiorRange{ | ||
return NSMakeRange(range.location + 9, range.length - 12); | ||
} | ||
|
||
+(NSString*)humanName{ | ||
return @"cdata"; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// CSSPartMatcher.h | ||
// Thumbprint | ||
// | ||
// Created by Lee Buck on 4/19/09. | ||
// Copyright 2009 Blue Bright Ventures. All rights reserved. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// Commercial licences without many of the obligations of GPL | ||
// are available for a nomial fee at [email protected]. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "Element.h" | ||
@class CSSSelectorMatcher; | ||
|
||
/** | ||
* Responsible for representing a successful match on a part. | ||
* It is presented elements in an attempt to complete the next part of the match | ||
* | ||
*/ | ||
@interface CSSPartMatcher : NSObject { | ||
CSSSelectorMatcher* selectorMatcher; // not retained | ||
Element* matchedElement; | ||
int matchedPartIndex; | ||
NSMutableArray* matchersForNextPart; | ||
} | ||
@property (nonatomic, retain) Element* matchedElement; | ||
@property int matchedPartIndex; | ||
|
||
-(id)initWithElement:(Element*) anElement selectorMatcher:(CSSSelectorMatcher*)aSelectorMatcher; | ||
//-(void)pruneMatchesForElement:(Element*)anElement; | ||
-(BOOL)matchNextElement:(Element*) nextElement forIndex: (int) index; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// | ||
// CSSPartMatcher.m | ||
// Thumbprint | ||
// | ||
// Created by Lee Buck on 4/19/09. | ||
// Copyright 2009 Blue Bright Ventures. All rights reserved. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// Commercial licences without many of the obligations of GPL | ||
// are available for a nomial fee at [email protected]. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
#import "CSSPartMatcher.h" | ||
#import "CSSSelectorPart.h" | ||
#import "CSSSelectorMatcher.h" | ||
|
||
@implementation CSSPartMatcher | ||
|
||
@synthesize matchedElement, matchedPartIndex; | ||
|
||
-(id)initWithElement:(Element*) anElement selectorMatcher:(CSSSelectorMatcher*)aSelectorMatcher{ | ||
self = [super init]; | ||
matchedElement = [anElement retain]; | ||
selectorMatcher = aSelectorMatcher; | ||
return self; | ||
} | ||
|
||
-(void)dealloc{ | ||
// NSLog(@"pruned: %@", [self description]); | ||
[matchedElement release]; | ||
[matchersForNextPart release]; | ||
[super dealloc]; | ||
} | ||
|
||
/* we don't do this yet... | ||
-(void)pruneMatchesForElement: (Element*)anElement{ | ||
if (!matchersForNextPart) return; | ||
for (CSSPartMatcher* match in matchersForNextPart){ | ||
if ([match scopeElement] == anElement) | ||
[matchersForNextPart removeObject: match]; | ||
else | ||
[match pruneMatchesForElement: anElement]; | ||
} | ||
} | ||
*/ | ||
|
||
-(void)addNextMatch:(Element*)nextElement withIndex:(int)index{ | ||
CSSPartMatcher* nextMatch = [[CSSPartMatcher alloc] initWithElement: nextElement selectorMatcher: selectorMatcher]; | ||
nextMatch.matchedPartIndex = index; | ||
if (!matchersForNextPart) | ||
matchersForNextPart = [[NSMutableArray alloc] initWithCapacity: 4]; | ||
[matchersForNextPart addObject: nextMatch]; | ||
[nextMatch release]; | ||
} | ||
|
||
-(BOOL)matchNextElement:(Element*) nextElement forIndex: (int) index{ | ||
CSSSelectorPart* nextPart = [[selectorMatcher selector] partAtIndex: index]; | ||
CSSVerb nextVerb = [[selectorMatcher selector] verbAtIndex: index]; | ||
BOOL verbMatches = NO; | ||
if ([nextPart matchesElement: nextElement]){ | ||
if (nextVerb == CSSVerbAny) | ||
verbMatches = YES; | ||
else if (nextVerb == CSSVerbDescendant) | ||
verbMatches = [nextElement hasAncestor: self.matchedElement];//wasteful to not prune matches as they go out of scope | ||
else if (nextVerb == CSSVerbChild) | ||
verbMatches = nextElement.parent == self.matchedElement; | ||
else if (nextVerb == CSSVerbSuccessor) | ||
verbMatches = nextElement == self.matchedElement.nextSybling; | ||
} | ||
|
||
BOOL completeMatch = verbMatches && (index == [[selectorMatcher selector] countOfParts] - 1); | ||
|
||
if (matchersForNextPart){ | ||
for (CSSPartMatcher* match in matchersForNextPart){ | ||
completeMatch = completeMatch || [match matchNextElement: nextElement forIndex: index + 1]; | ||
} | ||
} | ||
|
||
if (!completeMatch && verbMatches)//actually part and verb match | ||
[self addNextMatch: nextElement withIndex: index]; | ||
|
||
return completeMatch; | ||
} | ||
|
||
-(CSSSelectorPart*)matchedPart{ | ||
return [[selectorMatcher selector] partAtIndex: matchedPartIndex]; | ||
} | ||
|
||
-(NSString*)description{ | ||
return [NSString stringWithFormat: @"%@ matched %@ -- %i matchersForNextPart", [[self matchedPart] description], [matchedElement description], (matchersForNextPart) ? [matchersForNextPart count] : 0]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// CSSSelector.h | ||
// Thumbprint | ||
// | ||
// Created by Lee Buck on 4/17/09. | ||
// Copyright 2009 Blue Bright Ventures. All rights reserved. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// Commercial licences without many of the obligations of GPL | ||
// are available for a nomial fee at [email protected]. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "Element.h" | ||
|
||
@class CSSSelectorMatcher; | ||
@class CSSSelectorPart; | ||
|
||
#define CSSVerbChild @" > " | ||
#define CSSVerbSuccessor @" + " | ||
#define CSSVerbDescendant @" " | ||
#define CSSVerbAny @"" | ||
#define CSSVerb NSString* | ||
|
||
/** | ||
* CSSSelector is responsible for modeling a chain of CSSSelectorParts. For example | ||
* | ||
* body a.link | ||
* | ||
* is a chain of two parts "body" and "a.link" | ||
* | ||
* Parts are joined by "verbs" which correspond to symbols " ", "+", and ">" | ||
* These parts define the relative position of the second part to the first | ||
* Supported parts are: | ||
* space within - the second part must match an Element within the | ||
* Element matching the first part | ||
* | ||
* > child - the second part must match an Element whose parent is | ||
* the Element matching the first part | ||
* | ||
* + successor - the second part must match an Element whose previous | ||
* sybling was the Element matching the first part | ||
*/ | ||
|
||
@interface CSSSelector : NSObject { | ||
NSMutableArray* chain; | ||
} | ||
-(id)initWithString:(NSString*)string; | ||
-(NSString*)description; | ||
|
||
-(int)countOfParts; | ||
-(CSSSelectorPart*)partAtIndex:(int)index; | ||
-(CSSVerb)verbAtIndex:(int)index; | ||
-(CSSVerb)verbAfterIndex:(int)index; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// | ||
// CSSSelector.m | ||
// Thumbprint | ||
// | ||
// Created by Lee Buck on 4/17/09. | ||
// Copyright 2009 Blue Bright Ventures. All rights reserved. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// Commercial licences without many of the obligations of GPL | ||
// are available for a nomial fee at [email protected]. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
|
||
#import "CSSSelector.h" | ||
#import "CSSSelectorPart.h" | ||
#import "NSString_HTML.h" | ||
#import "CSSSelectorMatcher.h" | ||
|
||
|
||
@implementation CSSSelector | ||
|
||
|
||
-(id)initWithString:(NSString*)string{ | ||
CFStringInlineBuffer buffer; | ||
CFRange range = CFRangeMake(0, [string length]); | ||
CFStringInitInlineBuffer((CFStringRef)string, &buffer, range); | ||
|
||
chain = [[NSMutableArray alloc] initWithCapacity: 10]; | ||
unichar c; | ||
CFIndex index = 0; | ||
while (c = skipWhitespace(&buffer, &index)){ | ||
CSSSelectorPart* part = [[CSSSelectorPart alloc] initWithIndex: &index inBuffer: &buffer]; | ||
[chain addObject: part]; | ||
[part release]; | ||
|
||
c = skipWhitespace(&buffer, &index); | ||
if (!c) break; | ||
|
||
if (c=='+'){ | ||
[chain addObject: CSSVerbSuccessor]; | ||
index++; | ||
} | ||
else if (c=='>'){ | ||
[chain addObject: CSSVerbChild]; | ||
index++; | ||
} | ||
else | ||
[chain addObject: CSSVerbDescendant]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
-(void)dealloc{ | ||
// NSLog(@"disposing of %@", [self description]); | ||
[chain release]; | ||
[super dealloc]; | ||
} | ||
|
||
-(NSString*)description{ | ||
NSMutableString* result = [NSMutableString string]; | ||
for (id item in chain){ | ||
[result appendString: [item description]]; | ||
} | ||
return result; | ||
} | ||
|
||
-(int)countOfParts{ | ||
return ([chain count] + 1) / 2; | ||
} | ||
-(CSSSelectorPart*)partAtIndex:(int)index{ | ||
return [chain objectAtIndex: index * 2]; | ||
} | ||
|
||
-(CSSVerb)verbAtIndex:(int)index{ | ||
return (index > 0) ? [chain objectAtIndex: index * 2 - 1] : CSSVerbAny; | ||
} | ||
|
||
// sometime we need to access the next verb after an index... see scopingElement | ||
-(CSSVerb)verbAfterIndex:(int)index{ | ||
return (index < [self countOfParts] - 1) ? [self verbAtIndex: index + 1] : CSSVerbAny; | ||
} | ||
|
||
@end | ||
|
||
|
Oops, something went wrong.