rb-fsevent 0.4.3.1 → 0.9.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +3 -2
- data/ext/fsevent_watch/LICENSE +21 -0
- data/ext/fsevent_watch/fsevent_watch.xcodeproj/project.pbxproj +230 -0
- data/ext/fsevent_watch/fsevent_watch/TSICTString.c +394 -0
- data/ext/fsevent_watch/fsevent_watch/TSICTString.h +74 -0
- data/ext/fsevent_watch/fsevent_watch/cli.c +160 -0
- data/ext/fsevent_watch/fsevent_watch/cli.h +39 -0
- data/ext/fsevent_watch/fsevent_watch/common.h +33 -0
- data/ext/fsevent_watch/fsevent_watch/compat.h +40 -0
- data/ext/fsevent_watch/fsevent_watch/main.c +486 -0
- data/ext/rakefile.rb +47 -0
- data/ext/rb-fsevent.xcconfig +19 -0
- data/lib/rb-fsevent/version.rb +1 -1
- metadata +52 -77
- data/ext/extconf.rb +0 -61
- data/ext/fsevent/fsevent_watch.c +0 -226
data/README.rdoc
CHANGED
@@ -4,8 +4,9 @@ Very simple & usable Mac OSX FSEvents API
|
|
4
4
|
|
5
5
|
- RubyCocoa not required!
|
6
6
|
- Signals are working (really)
|
7
|
-
- Tested on MRI 1.8.7 & 1.9.2
|
8
|
-
- Tested on
|
7
|
+
- Tested on MRI 1.8.7 & 1.9.2, JRuby 1.6.3
|
8
|
+
- Tested on 10.6 & 10.7 (though 10.5 should work just as well)
|
9
|
+
- Tested with XCode 3.2.6, 4.0.2, 4.1, 4.2b5
|
9
10
|
|
10
11
|
== Install
|
11
12
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2011 Travis Tilley
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
@@ -0,0 +1,230 @@
|
|
1
|
+
// !$*UTF8*$!
|
2
|
+
{
|
3
|
+
archiveVersion = 1;
|
4
|
+
classes = {
|
5
|
+
};
|
6
|
+
objectVersion = 46;
|
7
|
+
objects = {
|
8
|
+
|
9
|
+
/* Begin PBXBuildFile section */
|
10
|
+
6A20BF7F13FC9BC000C6C442 /* cli.c in Sources */ = {isa = PBXBuildFile; fileRef = 6A20BF7C13FC9BC000C6C442 /* cli.c */; };
|
11
|
+
6A57F70413F5E614000BE6A9 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A57F70313F5E614000BE6A9 /* CoreServices.framework */; };
|
12
|
+
6A57F70713F5E614000BE6A9 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 6A57F70613F5E614000BE6A9 /* main.c */; };
|
13
|
+
6A81FCE8143429DF00F83EDD /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A81FCE7143429DE00F83EDD /* CoreFoundation.framework */; };
|
14
|
+
6A81FCEC14342A6300F83EDD /* TSICTString.c in Sources */ = {isa = PBXBuildFile; fileRef = 6A81FCEA14342A6300F83EDD /* TSICTString.c */; };
|
15
|
+
/* End PBXBuildFile section */
|
16
|
+
|
17
|
+
/* Begin PBXFileReference section */
|
18
|
+
6A20BF7C13FC9BC000C6C442 /* cli.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cli.c; sourceTree = "<group>"; };
|
19
|
+
6A20BF7D13FC9BC000C6C442 /* cli.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cli.h; sourceTree = "<group>"; };
|
20
|
+
6A20BF7E13FC9BC000C6C442 /* common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = common.h; sourceTree = "<group>"; };
|
21
|
+
6A57F6FF13F5E614000BE6A9 /* fsevent_watch */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = fsevent_watch; sourceTree = BUILT_PRODUCTS_DIR; };
|
22
|
+
6A57F70313F5E614000BE6A9 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
|
23
|
+
6A57F70613F5E614000BE6A9 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
|
24
|
+
6A81FCE7143429DE00F83EDD /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
|
25
|
+
6A81FCEA14342A6300F83EDD /* TSICTString.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = TSICTString.c; sourceTree = "<group>"; };
|
26
|
+
6A81FCEB14342A6300F83EDD /* TSICTString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TSICTString.h; sourceTree = "<group>"; };
|
27
|
+
6AD3022F13F8D758007F24E8 /* compat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = compat.h; sourceTree = "<group>"; };
|
28
|
+
/* End PBXFileReference section */
|
29
|
+
|
30
|
+
/* Begin PBXFrameworksBuildPhase section */
|
31
|
+
6A57F6FC13F5E614000BE6A9 /* Frameworks */ = {
|
32
|
+
isa = PBXFrameworksBuildPhase;
|
33
|
+
buildActionMask = 2147483647;
|
34
|
+
files = (
|
35
|
+
6A81FCE8143429DF00F83EDD /* CoreFoundation.framework in Frameworks */,
|
36
|
+
6A57F70413F5E614000BE6A9 /* CoreServices.framework in Frameworks */,
|
37
|
+
);
|
38
|
+
runOnlyForDeploymentPostprocessing = 0;
|
39
|
+
};
|
40
|
+
/* End PBXFrameworksBuildPhase section */
|
41
|
+
|
42
|
+
/* Begin PBXGroup section */
|
43
|
+
6A57F6F413F5E614000BE6A9 = {
|
44
|
+
isa = PBXGroup;
|
45
|
+
children = (
|
46
|
+
6A57F70513F5E614000BE6A9 /* fsevent_watch */,
|
47
|
+
6A57F70213F5E614000BE6A9 /* Frameworks */,
|
48
|
+
6A57F70013F5E614000BE6A9 /* Products */,
|
49
|
+
);
|
50
|
+
indentWidth = 2;
|
51
|
+
sourceTree = "<group>";
|
52
|
+
tabWidth = 2;
|
53
|
+
};
|
54
|
+
6A57F70013F5E614000BE6A9 /* Products */ = {
|
55
|
+
isa = PBXGroup;
|
56
|
+
children = (
|
57
|
+
6A57F6FF13F5E614000BE6A9 /* fsevent_watch */,
|
58
|
+
);
|
59
|
+
name = Products;
|
60
|
+
sourceTree = "<group>";
|
61
|
+
};
|
62
|
+
6A57F70213F5E614000BE6A9 /* Frameworks */ = {
|
63
|
+
isa = PBXGroup;
|
64
|
+
children = (
|
65
|
+
6A81FCE7143429DE00F83EDD /* CoreFoundation.framework */,
|
66
|
+
6A57F70313F5E614000BE6A9 /* CoreServices.framework */,
|
67
|
+
);
|
68
|
+
name = Frameworks;
|
69
|
+
sourceTree = "<group>";
|
70
|
+
};
|
71
|
+
6A57F70513F5E614000BE6A9 /* fsevent_watch */ = {
|
72
|
+
isa = PBXGroup;
|
73
|
+
children = (
|
74
|
+
6A81FCEA14342A6300F83EDD /* TSICTString.c */,
|
75
|
+
6A81FCEB14342A6300F83EDD /* TSICTString.h */,
|
76
|
+
6A20BF7C13FC9BC000C6C442 /* cli.c */,
|
77
|
+
6A20BF7D13FC9BC000C6C442 /* cli.h */,
|
78
|
+
6A20BF7E13FC9BC000C6C442 /* common.h */,
|
79
|
+
6A57F70613F5E614000BE6A9 /* main.c */,
|
80
|
+
6AD3022F13F8D758007F24E8 /* compat.h */,
|
81
|
+
);
|
82
|
+
path = fsevent_watch;
|
83
|
+
sourceTree = "<group>";
|
84
|
+
};
|
85
|
+
/* End PBXGroup section */
|
86
|
+
|
87
|
+
/* Begin PBXNativeTarget section */
|
88
|
+
6A57F6FE13F5E614000BE6A9 /* fsevent_watch */ = {
|
89
|
+
isa = PBXNativeTarget;
|
90
|
+
buildConfigurationList = 6A57F70C13F5E614000BE6A9 /* Build configuration list for PBXNativeTarget "fsevent_watch" */;
|
91
|
+
buildPhases = (
|
92
|
+
6A57F6FB13F5E614000BE6A9 /* Sources */,
|
93
|
+
6A57F6FC13F5E614000BE6A9 /* Frameworks */,
|
94
|
+
);
|
95
|
+
buildRules = (
|
96
|
+
);
|
97
|
+
dependencies = (
|
98
|
+
);
|
99
|
+
name = fsevent_watch;
|
100
|
+
productName = fsevent_watch;
|
101
|
+
productReference = 6A57F6FF13F5E614000BE6A9 /* fsevent_watch */;
|
102
|
+
productType = "com.apple.product-type.tool";
|
103
|
+
};
|
104
|
+
/* End PBXNativeTarget section */
|
105
|
+
|
106
|
+
/* Begin PBXProject section */
|
107
|
+
6A57F6F613F5E614000BE6A9 /* Project object */ = {
|
108
|
+
isa = PBXProject;
|
109
|
+
attributes = {
|
110
|
+
LastUpgradeCheck = 0420;
|
111
|
+
ORGANIZATIONNAME = TeaspoonOfInsanity;
|
112
|
+
};
|
113
|
+
buildConfigurationList = 6A57F6F913F5E614000BE6A9 /* Build configuration list for PBXProject "fsevent_watch" */;
|
114
|
+
compatibilityVersion = "Xcode 3.2";
|
115
|
+
developmentRegion = English;
|
116
|
+
hasScannedForEncodings = 0;
|
117
|
+
knownRegions = (
|
118
|
+
en,
|
119
|
+
);
|
120
|
+
mainGroup = 6A57F6F413F5E614000BE6A9;
|
121
|
+
productRefGroup = 6A57F70013F5E614000BE6A9 /* Products */;
|
122
|
+
projectDirPath = "";
|
123
|
+
projectRoot = "";
|
124
|
+
targets = (
|
125
|
+
6A57F6FE13F5E614000BE6A9 /* fsevent_watch */,
|
126
|
+
);
|
127
|
+
};
|
128
|
+
/* End PBXProject section */
|
129
|
+
|
130
|
+
/* Begin PBXSourcesBuildPhase section */
|
131
|
+
6A57F6FB13F5E614000BE6A9 /* Sources */ = {
|
132
|
+
isa = PBXSourcesBuildPhase;
|
133
|
+
buildActionMask = 2147483647;
|
134
|
+
files = (
|
135
|
+
6A57F70713F5E614000BE6A9 /* main.c in Sources */,
|
136
|
+
6A20BF7F13FC9BC000C6C442 /* cli.c in Sources */,
|
137
|
+
6A81FCEC14342A6300F83EDD /* TSICTString.c in Sources */,
|
138
|
+
);
|
139
|
+
runOnlyForDeploymentPostprocessing = 0;
|
140
|
+
};
|
141
|
+
/* End PBXSourcesBuildPhase section */
|
142
|
+
|
143
|
+
/* Begin XCBuildConfiguration section */
|
144
|
+
6A57F70A13F5E614000BE6A9 /* Debug */ = {
|
145
|
+
isa = XCBuildConfiguration;
|
146
|
+
buildSettings = {
|
147
|
+
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
|
148
|
+
COPY_PHASE_STRIP = NO;
|
149
|
+
DEBUG_INFORMATION_FORMAT = dwarf;
|
150
|
+
GCC_C_LANGUAGE_STANDARD = gnu99;
|
151
|
+
GCC_DYNAMIC_NO_PIC = NO;
|
152
|
+
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
|
153
|
+
GCC_ENABLE_OBJC_GC = supported;
|
154
|
+
GCC_ENABLE_SSE3_EXTENSIONS = YES;
|
155
|
+
GCC_OPTIMIZATION_LEVEL = 0;
|
156
|
+
GCC_PREPROCESSOR_DEFINITIONS = (
|
157
|
+
"DEBUG=1",
|
158
|
+
"$(inherited)",
|
159
|
+
);
|
160
|
+
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
|
161
|
+
MACOSX_DEPLOYMENT_TARGET = 10.5;
|
162
|
+
ONLY_ACTIVE_ARCH = NO;
|
163
|
+
SDKROOT = macosx;
|
164
|
+
STRIP_INSTALLED_PRODUCT = NO;
|
165
|
+
WARNING_CFLAGS = (
|
166
|
+
"-Wall",
|
167
|
+
"-Wextra",
|
168
|
+
"-fcatch-undefined-behavior",
|
169
|
+
);
|
170
|
+
};
|
171
|
+
name = Debug;
|
172
|
+
};
|
173
|
+
6A57F70B13F5E614000BE6A9 /* Release */ = {
|
174
|
+
isa = XCBuildConfiguration;
|
175
|
+
buildSettings = {
|
176
|
+
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
|
177
|
+
COPY_PHASE_STRIP = YES;
|
178
|
+
DEBUG_INFORMATION_FORMAT = dwarf;
|
179
|
+
GCC_C_LANGUAGE_STANDARD = gnu99;
|
180
|
+
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
|
181
|
+
GCC_ENABLE_OBJC_GC = supported;
|
182
|
+
GCC_ENABLE_SSE3_EXTENSIONS = YES;
|
183
|
+
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
|
184
|
+
MACOSX_DEPLOYMENT_TARGET = 10.5;
|
185
|
+
ONLY_ACTIVE_ARCH = NO;
|
186
|
+
SDKROOT = macosx;
|
187
|
+
};
|
188
|
+
name = Release;
|
189
|
+
};
|
190
|
+
6A57F70D13F5E614000BE6A9 /* Debug */ = {
|
191
|
+
isa = XCBuildConfiguration;
|
192
|
+
buildSettings = {
|
193
|
+
MACH_O_TYPE = mh_execute;
|
194
|
+
PRODUCT_NAME = "$(TARGET_NAME)";
|
195
|
+
};
|
196
|
+
name = Debug;
|
197
|
+
};
|
198
|
+
6A57F70E13F5E614000BE6A9 /* Release */ = {
|
199
|
+
isa = XCBuildConfiguration;
|
200
|
+
buildSettings = {
|
201
|
+
MACH_O_TYPE = mh_execute;
|
202
|
+
PRODUCT_NAME = "$(TARGET_NAME)";
|
203
|
+
};
|
204
|
+
name = Release;
|
205
|
+
};
|
206
|
+
/* End XCBuildConfiguration section */
|
207
|
+
|
208
|
+
/* Begin XCConfigurationList section */
|
209
|
+
6A57F6F913F5E614000BE6A9 /* Build configuration list for PBXProject "fsevent_watch" */ = {
|
210
|
+
isa = XCConfigurationList;
|
211
|
+
buildConfigurations = (
|
212
|
+
6A57F70A13F5E614000BE6A9 /* Debug */,
|
213
|
+
6A57F70B13F5E614000BE6A9 /* Release */,
|
214
|
+
);
|
215
|
+
defaultConfigurationIsVisible = 0;
|
216
|
+
defaultConfigurationName = Release;
|
217
|
+
};
|
218
|
+
6A57F70C13F5E614000BE6A9 /* Build configuration list for PBXNativeTarget "fsevent_watch" */ = {
|
219
|
+
isa = XCConfigurationList;
|
220
|
+
buildConfigurations = (
|
221
|
+
6A57F70D13F5E614000BE6A9 /* Debug */,
|
222
|
+
6A57F70E13F5E614000BE6A9 /* Release */,
|
223
|
+
);
|
224
|
+
defaultConfigurationIsVisible = 0;
|
225
|
+
defaultConfigurationName = Release;
|
226
|
+
};
|
227
|
+
/* End XCConfigurationList section */
|
228
|
+
};
|
229
|
+
rootObject = 6A57F6F613F5E614000BE6A9 /* Project object */;
|
230
|
+
}
|
@@ -0,0 +1,394 @@
|
|
1
|
+
//
|
2
|
+
// TSICTString.c
|
3
|
+
// TSITString
|
4
|
+
//
|
5
|
+
// Created by Travis Tilley on 9/27/11.
|
6
|
+
//
|
7
|
+
|
8
|
+
#include "TSICTString.h"
|
9
|
+
|
10
|
+
|
11
|
+
const char* const TNetstringTypes = ",#^!~}]Z";
|
12
|
+
const char* const OTNetstringTypes = ",#^!~{[Z";
|
13
|
+
const UInt8 TNetstringSeparator = ':';
|
14
|
+
|
15
|
+
TSITStringFormat TSITStringDefaultFormat = kTSITStringFormatTNetstring;
|
16
|
+
|
17
|
+
static const CFRange BeginningRange = {0,0};
|
18
|
+
|
19
|
+
static CFTypeID kCFDataTypeID = -1;
|
20
|
+
static CFTypeID kCFStringTypeID = -1;
|
21
|
+
static CFTypeID kCFNumberTypeID = -1;
|
22
|
+
static CFTypeID kCFBooleanTypeID = -1;
|
23
|
+
static CFTypeID kCFNullTypeID = -1;
|
24
|
+
static CFTypeID kCFArrayTypeID = -1;
|
25
|
+
static CFTypeID kCFDictionaryTypeID = -1;
|
26
|
+
|
27
|
+
|
28
|
+
__attribute__((constructor)) void Init_TSICTString(void)
|
29
|
+
{
|
30
|
+
kCFDataTypeID = CFDataGetTypeID();
|
31
|
+
kCFStringTypeID = CFStringGetTypeID();
|
32
|
+
kCFNumberTypeID = CFNumberGetTypeID();
|
33
|
+
kCFBooleanTypeID = CFBooleanGetTypeID();
|
34
|
+
kCFNullTypeID = CFNullGetTypeID();
|
35
|
+
kCFArrayTypeID = CFArrayGetTypeID();
|
36
|
+
kCFDictionaryTypeID = CFDictionaryGetTypeID();
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
void TSICTStringSetDefaultFormat(TSITStringFormat format)
|
41
|
+
{
|
42
|
+
if (format == kTSITStringFormatDefault) {
|
43
|
+
TSITStringDefaultFormat = kTSITStringFormatTNetstring;
|
44
|
+
} else {
|
45
|
+
TSITStringDefaultFormat = format;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
TSITStringFormat TSICTStringGetDefaultFormat(void)
|
50
|
+
{
|
51
|
+
return TSITStringDefaultFormat;
|
52
|
+
}
|
53
|
+
|
54
|
+
|
55
|
+
void TSICTStringDestroy(TStringIRep* rep)
|
56
|
+
{
|
57
|
+
CFRelease(rep->data);
|
58
|
+
free(rep->length);
|
59
|
+
free(rep);
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
static inline TStringIRep* TSICTStringCreateWithDataOfTypeAndFormat(CFDataRef data, TSITStringTag type, TSITStringFormat format)
|
64
|
+
{
|
65
|
+
if (format == kTSITStringFormatDefault) {
|
66
|
+
format = TSICTStringGetDefaultFormat();
|
67
|
+
}
|
68
|
+
|
69
|
+
TStringIRep* rep = calloc(1, sizeof(TStringIRep));
|
70
|
+
rep->data = CFDataCreateCopy(kCFAllocatorDefault, data);
|
71
|
+
rep->type = type;
|
72
|
+
rep->format = format;
|
73
|
+
rep->length = calloc(10, sizeof(char));
|
74
|
+
|
75
|
+
CFIndex len = CFDataGetLength(rep->data);
|
76
|
+
if (snprintf(rep->length, 10, "%lu", len)) {
|
77
|
+
return rep;
|
78
|
+
} else {
|
79
|
+
TSICTStringDestroy(rep);
|
80
|
+
return NULL;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
static inline CFDataRef TSICTStringCreateDataFromIntermediateRepresentation(TStringIRep* rep)
|
85
|
+
{
|
86
|
+
CFIndex len = CFDataGetLength(rep->data);
|
87
|
+
CFMutableDataRef buffer = CFDataCreateMutableCopy(kCFAllocatorDefault, (len + 12), rep->data);
|
88
|
+
UInt8* bufferBytes = CFDataGetMutableBytePtr(buffer);
|
89
|
+
|
90
|
+
size_t prefixLength = strlen(rep->length) + 1;
|
91
|
+
CFDataReplaceBytes(buffer, BeginningRange, (const UInt8*)rep->length, prefixLength);
|
92
|
+
|
93
|
+
if (rep->format == kTSITStringFormatTNetstring) {
|
94
|
+
const UInt8 ftag = TNetstringTypes[rep->type];
|
95
|
+
CFDataAppendBytes(buffer, &ftag, 1);
|
96
|
+
bufferBytes[(prefixLength - 1)] = TNetstringSeparator;
|
97
|
+
} else if (rep->format == kTSITStringFormatOTNetstring) {
|
98
|
+
const UInt8 ftag = OTNetstringTypes[rep->type];
|
99
|
+
bufferBytes[(prefixLength - 1)] = ftag;
|
100
|
+
}
|
101
|
+
|
102
|
+
CFDataRef dataRep = CFDataCreateCopy(kCFAllocatorDefault, buffer);
|
103
|
+
CFRelease(buffer);
|
104
|
+
|
105
|
+
return dataRep;
|
106
|
+
}
|
107
|
+
|
108
|
+
static inline CFStringRef TSICTStringCreateStringFromIntermediateRepresentation(TStringIRep* rep)
|
109
|
+
{
|
110
|
+
CFDataRef data = TSICTStringCreateDataFromIntermediateRepresentation(rep);
|
111
|
+
CFStringRef string = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, data, kCFStringEncodingUTF8);
|
112
|
+
CFRelease(data);
|
113
|
+
return string;
|
114
|
+
}
|
115
|
+
|
116
|
+
static inline CFDataRef TSICTStringCreateDataWithDataOfTypeAndFormat(CFDataRef data, TSITStringTag type, TSITStringFormat format)
|
117
|
+
{
|
118
|
+
CFRetain(data);
|
119
|
+
|
120
|
+
if (format == kTSITStringFormatDefault) {
|
121
|
+
format = TSICTStringGetDefaultFormat();
|
122
|
+
}
|
123
|
+
|
124
|
+
TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(data, type, format);
|
125
|
+
if (rep == NULL) {
|
126
|
+
return NULL;
|
127
|
+
}
|
128
|
+
|
129
|
+
CFDataRef result = TSICTStringCreateDataFromIntermediateRepresentation(rep);
|
130
|
+
|
131
|
+
TSICTStringDestroy(rep);
|
132
|
+
CFRelease(data);
|
133
|
+
|
134
|
+
return result;
|
135
|
+
}
|
136
|
+
|
137
|
+
static inline void TSICTStringAppendObjectToMutableDataWithFormat(CFTypeRef object, CFMutableDataRef buffer, TSITStringFormat format)
|
138
|
+
{
|
139
|
+
if (object == NULL) {
|
140
|
+
object = kCFNull;
|
141
|
+
}
|
142
|
+
|
143
|
+
CFRetain(object);
|
144
|
+
|
145
|
+
TStringIRep* objRep = TSICTStringCreateWithObjectAndFormat(object, format);
|
146
|
+
CFDataRef objData = TSICTStringCreateDataFromIntermediateRepresentation(objRep);
|
147
|
+
CFDataAppendBytes(buffer, (CFDataGetBytePtr(objData)), CFDataGetLength(objData));
|
148
|
+
CFRelease(objData);
|
149
|
+
TSICTStringDestroy(objRep);
|
150
|
+
|
151
|
+
CFRelease(object);
|
152
|
+
}
|
153
|
+
|
154
|
+
static void ArrayBufferAppendCallback(const void* item, void* context)
|
155
|
+
{
|
156
|
+
TStringCollectionCallbackContext* cx = (TStringCollectionCallbackContext*)context;
|
157
|
+
CFMutableDataRef buffer = cx->buffer;
|
158
|
+
TSITStringFormat format = cx->format;
|
159
|
+
|
160
|
+
TSICTStringAppendObjectToMutableDataWithFormat(item, buffer, format);
|
161
|
+
}
|
162
|
+
|
163
|
+
static void DictionaryBufferAppendCallback(const void* key, const void* value, void* context)
|
164
|
+
{
|
165
|
+
TStringCollectionCallbackContext* cx = (TStringCollectionCallbackContext*)context;
|
166
|
+
CFMutableDataRef buffer = cx->buffer;
|
167
|
+
TSITStringFormat format = cx->format;
|
168
|
+
|
169
|
+
TSICTStringAppendObjectToMutableDataWithFormat(key, buffer, format);
|
170
|
+
TSICTStringAppendObjectToMutableDataWithFormat(value, buffer, format);
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
CFDataRef TSICTStringCreateRenderedData(TStringIRep* rep)
|
175
|
+
{
|
176
|
+
return TSICTStringCreateDataFromIntermediateRepresentation(rep);
|
177
|
+
}
|
178
|
+
|
179
|
+
CFDataRef TSICTStringCreateRenderedDataFromObjectWithFormat(CFTypeRef object, TSITStringFormat format)
|
180
|
+
{
|
181
|
+
if (object == NULL) {
|
182
|
+
object = kCFNull;
|
183
|
+
}
|
184
|
+
|
185
|
+
CFRetain(object);
|
186
|
+
|
187
|
+
TStringIRep* rep = TSICTStringCreateWithObjectAndFormat(object, format);
|
188
|
+
CFDataRef data = TSICTStringCreateDataFromIntermediateRepresentation(rep);
|
189
|
+
|
190
|
+
TSICTStringDestroy(rep);
|
191
|
+
CFRelease(object);
|
192
|
+
|
193
|
+
return data;
|
194
|
+
}
|
195
|
+
|
196
|
+
CFStringRef TSICTStringCreateRenderedString(TStringIRep* rep)
|
197
|
+
{
|
198
|
+
return TSICTStringCreateStringFromIntermediateRepresentation(rep);
|
199
|
+
}
|
200
|
+
|
201
|
+
CFStringRef TSICTStringCreateRenderedStringFromObjectWithFormat(CFTypeRef object, TSITStringFormat format)
|
202
|
+
{
|
203
|
+
if (object == NULL) {
|
204
|
+
object = kCFNull;
|
205
|
+
}
|
206
|
+
|
207
|
+
CFRetain(object);
|
208
|
+
|
209
|
+
TStringIRep* rep = TSICTStringCreateWithObjectAndFormat(object, format);
|
210
|
+
CFStringRef string = TSICTStringCreateStringFromIntermediateRepresentation(rep);
|
211
|
+
|
212
|
+
TSICTStringDestroy(rep);
|
213
|
+
CFRelease(object);
|
214
|
+
|
215
|
+
return string;
|
216
|
+
}
|
217
|
+
|
218
|
+
|
219
|
+
TStringIRep* TSICTStringCreateWithObjectAndFormat(CFTypeRef object, TSITStringFormat format)
|
220
|
+
{
|
221
|
+
if (object == NULL) {
|
222
|
+
return TSICTStringCreateNullWithFormat(format);
|
223
|
+
}
|
224
|
+
CFRetain(object);
|
225
|
+
|
226
|
+
CFTypeID cfType = CFGetTypeID(object);
|
227
|
+
TStringIRep* rep = NULL;
|
228
|
+
|
229
|
+
if (cfType == kCFDataTypeID) {
|
230
|
+
rep = TSICTStringCreateWithDataOfTypeAndFormat(object, kTSITStringTagString, format);
|
231
|
+
} else if (cfType == kCFStringTypeID) {
|
232
|
+
rep = TSICTStringCreateWithStringAndFormat(object, format);
|
233
|
+
} else if (cfType == kCFNumberTypeID) {
|
234
|
+
rep = TSICTStringCreateWithNumberAndFormat(object, format);
|
235
|
+
} else if (cfType == kCFBooleanTypeID) {
|
236
|
+
if (CFBooleanGetValue(object)) {
|
237
|
+
rep = TSICTStringCreateTrueWithFormat(format);
|
238
|
+
} else {
|
239
|
+
rep = TSICTStringCreateFalseWithFormat(format);
|
240
|
+
}
|
241
|
+
} else if (cfType == kCFNullTypeID) {
|
242
|
+
rep = TSICTStringCreateNullWithFormat(format);
|
243
|
+
} else if (cfType == kCFArrayTypeID) {
|
244
|
+
rep = TSICTStringCreateWithArrayAndFormat(object, format);
|
245
|
+
} else if (cfType == kCFDictionaryTypeID) {
|
246
|
+
rep = TSICTStringCreateWithDictionaryAndFormat(object, format);
|
247
|
+
} else {
|
248
|
+
rep = TSICTStringCreateInvalidWithFormat(format);
|
249
|
+
}
|
250
|
+
|
251
|
+
CFRelease(object);
|
252
|
+
return rep;
|
253
|
+
}
|
254
|
+
|
255
|
+
TStringIRep* TSICTStringCreateWithStringAndFormat(CFStringRef string, TSITStringFormat format)
|
256
|
+
{
|
257
|
+
CFRetain(string);
|
258
|
+
CFDataRef data = CFStringCreateExternalRepresentation(kCFAllocatorDefault, string, kCFStringEncodingUTF8, '?');
|
259
|
+
TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(data, kTSITStringTagString, format);
|
260
|
+
CFRelease(data);
|
261
|
+
CFRelease(string);
|
262
|
+
return rep;
|
263
|
+
}
|
264
|
+
|
265
|
+
TStringIRep* TSICTStringCreateWithNumberAndFormat(CFNumberRef number, TSITStringFormat format)
|
266
|
+
{
|
267
|
+
CFRetain(number);
|
268
|
+
TSITStringTag tag = kTSITStringTagNumber;
|
269
|
+
CFDataRef data;
|
270
|
+
CFNumberType numType = CFNumberGetType(number);
|
271
|
+
|
272
|
+
switch(numType) {
|
273
|
+
case kCFNumberCharType:
|
274
|
+
{
|
275
|
+
int value;
|
276
|
+
if (CFNumberGetValue(number, kCFNumberIntType, &value)) {
|
277
|
+
if (value == 0 || value == 1) {
|
278
|
+
tag = kTSITStringTagBool;
|
279
|
+
} else {
|
280
|
+
tag = kTSITStringTagString;
|
281
|
+
}
|
282
|
+
}
|
283
|
+
break;
|
284
|
+
}
|
285
|
+
case kCFNumberFloat32Type:
|
286
|
+
case kCFNumberFloat64Type:
|
287
|
+
case kCFNumberFloatType:
|
288
|
+
case kCFNumberDoubleType:
|
289
|
+
{
|
290
|
+
tag = kTSITStringTagFloat;
|
291
|
+
break;
|
292
|
+
}
|
293
|
+
}
|
294
|
+
|
295
|
+
if (tag == kTSITStringTagBool) {
|
296
|
+
bool value;
|
297
|
+
CFNumberGetValue(number, kCFNumberIntType, &value);
|
298
|
+
if (value) {
|
299
|
+
data = CFDataCreate(kCFAllocatorDefault, (UInt8*)"true", 4);
|
300
|
+
} else {
|
301
|
+
data = CFDataCreate(kCFAllocatorDefault, (UInt8*)"false", 5);
|
302
|
+
}
|
303
|
+
} else if (tag == kTSITStringTagFloat) {
|
304
|
+
char buf[32];
|
305
|
+
char *p, *e;
|
306
|
+
double value;
|
307
|
+
|
308
|
+
CFNumberGetValue(number, numType, &value);
|
309
|
+
sprintf(buf, "%#.15g", value);
|
310
|
+
|
311
|
+
e = buf + strlen(buf);
|
312
|
+
p = e;
|
313
|
+
while (p[-1]=='0' && ('0' <= p[-2] && p[-2] <= '9')) {
|
314
|
+
p--;
|
315
|
+
}
|
316
|
+
memmove(p, e, strlen(e)+1);
|
317
|
+
|
318
|
+
data = CFDataCreate(kCFAllocatorDefault, (UInt8*)buf, strlen(buf));
|
319
|
+
} else {
|
320
|
+
char buf[32];
|
321
|
+
SInt64 value;
|
322
|
+
CFNumberGetValue(number, numType, &value);
|
323
|
+
sprintf(buf, "%lli", value);
|
324
|
+
data = CFDataCreate(kCFAllocatorDefault, (UInt8*)buf, strlen(buf));
|
325
|
+
}
|
326
|
+
|
327
|
+
TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(data, tag, format);
|
328
|
+
CFRelease(data);
|
329
|
+
CFRelease(number);
|
330
|
+
return rep;
|
331
|
+
}
|
332
|
+
|
333
|
+
TStringIRep* TSICTStringCreateTrueWithFormat(TSITStringFormat format)
|
334
|
+
{
|
335
|
+
CFDataRef data = CFDataCreate(kCFAllocatorDefault, (UInt8*)"true", 4);
|
336
|
+
TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(data, kTSITStringTagBool, format);
|
337
|
+
CFRelease(data);
|
338
|
+
return rep;
|
339
|
+
}
|
340
|
+
|
341
|
+
TStringIRep* TSICTStringCreateFalseWithFormat(TSITStringFormat format)
|
342
|
+
{
|
343
|
+
CFDataRef data = CFDataCreate(kCFAllocatorDefault, (UInt8*)"false", 5);
|
344
|
+
TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(data, kTSITStringTagBool, format);
|
345
|
+
CFRelease(data);
|
346
|
+
return rep;
|
347
|
+
}
|
348
|
+
|
349
|
+
TStringIRep* TSICTStringCreateNullWithFormat(TSITStringFormat format)
|
350
|
+
{
|
351
|
+
CFDataRef data = CFDataCreate(kCFAllocatorDefault, NULL, 0);
|
352
|
+
TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(data, kTSITStringTagNull, format);
|
353
|
+
CFRelease(data);
|
354
|
+
return rep;
|
355
|
+
}
|
356
|
+
|
357
|
+
TStringIRep* TSICTStringCreateInvalidWithFormat(TSITStringFormat format)
|
358
|
+
{
|
359
|
+
CFDataRef data = CFDataCreate(kCFAllocatorDefault, NULL, 0);
|
360
|
+
TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(data, kTSITStringTagInvalid, format);
|
361
|
+
CFRelease(data);
|
362
|
+
return rep;
|
363
|
+
}
|
364
|
+
|
365
|
+
TStringIRep* TSICTStringCreateWithArrayAndFormat(CFArrayRef array, TSITStringFormat format)
|
366
|
+
{
|
367
|
+
CFRetain(array);
|
368
|
+
|
369
|
+
CFMutableDataRef buffer = CFDataCreateMutable(kCFAllocatorDefault, 0);
|
370
|
+
|
371
|
+
CFRange all = CFRangeMake(0, CFArrayGetCount(array));
|
372
|
+
TStringCollectionCallbackContext cx = {buffer, format};
|
373
|
+
CFArrayApplyFunction(array, all, ArrayBufferAppendCallback, &cx);
|
374
|
+
|
375
|
+
TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(buffer, kTSITStringTagList, format);
|
376
|
+
CFRelease(buffer);
|
377
|
+
CFRelease(array);
|
378
|
+
return rep;
|
379
|
+
}
|
380
|
+
|
381
|
+
TStringIRep* TSICTStringCreateWithDictionaryAndFormat(CFDictionaryRef dictionary, TSITStringFormat format)
|
382
|
+
{
|
383
|
+
CFRetain(dictionary);
|
384
|
+
|
385
|
+
CFMutableDataRef buffer = CFDataCreateMutable(kCFAllocatorDefault, 0);
|
386
|
+
|
387
|
+
TStringCollectionCallbackContext cx = {buffer, format};
|
388
|
+
CFDictionaryApplyFunction(dictionary, DictionaryBufferAppendCallback, &cx);
|
389
|
+
|
390
|
+
TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(buffer, kTSITStringTagDict, format);
|
391
|
+
CFRelease(buffer);
|
392
|
+
CFRelease(dictionary);
|
393
|
+
return rep;
|
394
|
+
}
|