1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
<?
// Returns an array of sub-directories for $directory
function sub_directories ($directory, &$directories) {
if (file_exists($directory)) {
$directories[] = $directory;
} else {
$directories = array();
}
if ($handle = @opendir($directory)) {
while (($file = readdir($handle)) !== false) {
if (($file != '.') && ($file != '..') && ($file[0] != '.')) {
$path = "$directory/$file";
if (is_dir($path)) sub_directories($path, $directories);
}
}
closedir($handle);
}
}
class DocSetParser {
var $docset;
var $methods = array();
// Parse a single reference file
private function parse ($path, $class) {
$method = null;
$methods = array();
if ($lines = @file($path)) {
foreach ($lines as $line) {
// Parse instance method description
if ($method) {
if (preg_match("/<span.*data-abstract='(.*)'>/i", $line, $captures)) {
$methods[$method] = strip_tags($captures[1]);
$method = null;
}
}
// Found type definition tag
if (preg_match("/<h3 class=\"tight jump typeDef\">(\w+)<\/h3><p class=\"abstract\">(.*)<\/p>/i", $line, $captures)) {
// Read until the end </p> because I can't get preg_match to do this
$text = substr($captures[2], 0, (stripos($captures[2], "</p>")));
if (!$text) $text = $captures[2];
$methods[$captures[1]] = strip_tags($text);
}
// Found constant tag
if (preg_match("/<code class=\"jump constantName\">(\w+)<\/code><\/dt><dd><p>(.*)<\/p>/i", $line, $captures)) {
//print_r($captures);
// Read until the end </p> because I can't get preg_match to do this
$text = substr($captures[2], 0, (stripos($captures[2], "</p>")));
if (!$text) $text = $captures[2];
$methods[$captures[1]] = strip_tags($text);
}
// Found instance method tag
if (preg_match("<a href=\"#//apple_ref/occ/(instm|intfm|intfp|clm)+/([a-zA-Z:_]+)/([a-zA-Z:_]+)\">", $line, $captures)) {
//print_r($captures);
if ($captures[2] == $class) {
$method = $captures[3];
continue;
}
}
}
} else {
print("* Warning: Can't find the docset at $path.\n");
}
return $methods;
}
// Parses the reference index.html file for the path to the reference html file
private function parse_reference_index ($path) {
$lines = file($path);
foreach ($lines as $line) {
if (preg_match("/<meta id=\"refresh\" http-equiv=\"refresh\" CONTENT=\"0; URL=(.*)\">/i", $line, $captures)) {
return $captures[1];
}
}
}
public function parse_directory ($paths) {
foreach ($paths as $path) {
$path = $this->docset."/Contents/Resources/Documents/documentation".$path;
if (file_exists($path)) {
sub_directories($path, $sub_directories);
foreach ($sub_directories as $directory) {
$name = basename($directory);
if (preg_match("/^(\w+)_(class|protocol)$/i", $name, $captures)) {
$class = $captures[1];
$sub_path = $this->parse_reference_index("$directory/index.html");
if ($methods = $this->parse("$directory/$sub_path", $class)) {
$this->methods[$class] = $methods;
}
}
}
} else {
print("* Warning: The docset at $path can't be found.\n");
}
}
return true;
}
function __construct ($docset) {
$this->docset = $docset;
}
}
// Cocoa
//$path = "/Users/ryanjoseph/Desktop/com.apple.adc.documentation.AppleSnowLeopard.CoreReference.docset";
//$folders = array("/Cocoa/Reference");
// UIKIT
// $path = "/Users/ryanjoseph/Desktop/com.apple.adc.documentation.AppleiOS4_2.iOSLibrary.docset";
//$folders = array("/UIKit/Reference");
//$parser = new DocSetParser($path);
//$parser->parse_directory($folders);
//print_r($parser->methods);
?>
|