version_sorter 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,3 +9,10 @@ By pope.
9
9
  VersionSorter.sort(versions) # => ["1.0.3", "1.0.9", "1.0.10", "2.0"]
10
10
 
11
11
  <http://github.com/blog/521-speedy-version-sorting>
12
+
13
+ Install
14
+ -------
15
+
16
+ ## [Gemcutter](http://gemcutter.org)
17
+
18
+ $ gem install version_sorter
@@ -0,0 +1,435 @@
1
+ /*
2
+ * Copyright 2008 Google Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ #ifndef CMOCKERY_H_
17
+ #define CMOCKERY_H_
18
+ /*
19
+ * These headers or their equivalents should be included prior to including
20
+ * this header file.
21
+ *
22
+ * #include <stdarg.h>
23
+ * #include <stddef.h>
24
+ * #include <setjmp.h>
25
+ *
26
+ * This allows test applications to use custom definitions of C standard
27
+ * library functions and types.
28
+ */
29
+
30
+ // For those who are used to __func__ from gcc.
31
+ #ifndef __func__
32
+ #define __func__ __FUNCTION__
33
+ #endif
34
+
35
+ // Retrieves a return value for the current function.
36
+ #define mock() _mock(__func__, __FILE__, __LINE__)
37
+
38
+ /* Stores a value to be returned by the specified function later.
39
+ * The count parameter returns the number of times the value should be returned
40
+ * by mock(). If count is set to -1 the value will always be returned.
41
+ */
42
+ #define will_return(function, value) \
43
+ _will_return(#function, __FILE__, __LINE__, (void*)value, 1)
44
+ #define will_return_count(function, value, count) \
45
+ _will_return(#function, __FILE__, __LINE__, (void*)value, count)
46
+
47
+ /* Add a custom parameter checking function. If the event parameter is NULL
48
+ * the event structure is allocated internally by this function. If event
49
+ * parameter is provided it must be allocated on the heap and doesn't need to
50
+ * be deallocated by the caller.
51
+ */
52
+ #define expect_check(function, parameter, check_function, check_data) \
53
+ _expect_check(#function, #parameter, __FILE__, __LINE__, check_function, \
54
+ check_data)
55
+
56
+ /* Add an event to check a parameter, using check_expected(), against a set of
57
+ * values. See will_return() for a description of the count parameter.
58
+ */
59
+ #define expect_in_set(function, parameter, value_array) \
60
+ expect_in_set_count(function, parameter, value_array, 1)
61
+ #define expect_in_set_count(function, parameter, value_array, count) \
62
+ _expect_in_set(#function, #parameter, __FILE__, __LINE__, value_array, \
63
+ sizeof(value_array) / sizeof(value_array[0]), count)
64
+ #define expect_not_in_set(function, parameter, value_array) \
65
+ expect_not_in_set_count(function, parameter, value_array, 1)
66
+ #define expect_not_in_set_count(function, parameter, value_array, count) \
67
+ _expect_not_in_set( \
68
+ #function, #parameter, __FILE__, __LINE__, value_array, \
69
+ sizeof(value_array) / sizeof(value_array[0]), count)
70
+
71
+
72
+ /* Add an event to check a parameter, using check_expected(), against a
73
+ * signed range. Where range is minimum <= value <= maximum.
74
+ * See will_return() for a description of the count parameter.
75
+ */
76
+ #define expect_in_range(function, parameter, minimum, maximum) \
77
+ expect_in_range_count(function, parameter, minimum, maximum, 1)
78
+ #define expect_in_range_count(function, parameter, minimum, maximum, count) \
79
+ _expect_in_range(#function, #parameter, __FILE__, __LINE__, minimum, \
80
+ maximum, count)
81
+
82
+ /* Add an event to check a parameter, using check_expected(), against a
83
+ * signed range. Where range is value < minimum or value > maximum.
84
+ * See will_return() for a description of the count parameter.
85
+ */
86
+ #define expect_not_in_range(function, parameter, minimum, maximum) \
87
+ expect_not_in_range_count(function, parameter, minimum, maximum, 1)
88
+ #define expect_not_in_range_count(function, parameter, minimum, maximum, \
89
+ count) \
90
+ _expect_not_in_range(#function, #parameter, __FILE__, __LINE__, \
91
+ minimum, maximum, count)
92
+
93
+ /* Add an event to check whether a parameter, using check_expected(), is or
94
+ * isn't a value. See will_return() for a description of the count parameter.
95
+ */
96
+ #define expect_value(function, parameter, value) \
97
+ expect_value_count(function, parameter, value, 1)
98
+ #define expect_value_count(function, parameter, value, count) \
99
+ _expect_value(#function, #parameter, __FILE__, __LINE__, (void*)value, \
100
+ count)
101
+ #define expect_not_value(function, parameter, value) \
102
+ expect_not_value_count(function, parameter, value, 1)
103
+ #define expect_not_value_count(function, parameter, value, count) \
104
+ _expect_not_value(#function, #parameter, __FILE__, __LINE__, \
105
+ (void*)value, count)
106
+
107
+ /* Add an event to check whether a parameter, using check_expected(),
108
+ * is or isn't a string. See will_return() for a description of the count
109
+ * parameter.
110
+ */
111
+ #define expect_string(function, parameter, string) \
112
+ expect_string_count(function, parameter, string, 1)
113
+ #define expect_string_count(function, parameter, string, count) \
114
+ _expect_string(#function, #parameter, __FILE__, __LINE__, (void*)string, \
115
+ count)
116
+ #define expect_not_string(function, parameter, string) \
117
+ expect_not_string_count(function, parameter, string, 1)
118
+ #define expect_not_string_count(function, parameter, string, count) \
119
+ _expect_not_string(#function, #parameter, __FILE__, __LINE__, \
120
+ (void*)string, count)
121
+
122
+ /* Add an event to check whether a parameter, using check_expected() does or
123
+ * doesn't match an area of memory. See will_return() for a description of
124
+ * the count parameter.
125
+ */
126
+ #define expect_memory(function, parameter, memory, size) \
127
+ expect_memory_count(function, parameter, memory, size, 1)
128
+ #define expect_memory_count(function, parameter, memory, size, count) \
129
+ _expect_memory(#function, #parameter, __FILE__, __LINE__, (void*)memory, \
130
+ size, count)
131
+ #define expect_not_memory(function, parameter, memory, size) \
132
+ expect_not_memory_count(function, parameter, memory, size, 1)
133
+ #define expect_not_memory_count(function, parameter, memory, size, count) \
134
+ _expect_not_memory(#function, #parameter, __FILE__, __LINE__, \
135
+ (void*)memory, size, count)
136
+
137
+
138
+ /* Add an event to allow any value for a parameter checked using
139
+ * check_expected(). See will_return() for a description of the count
140
+ * parameter.
141
+ */
142
+ #define expect_any(function, parameter) \
143
+ expect_any_count(function, parameter, 1)
144
+ #define expect_any_count(function, parameter, count) \
145
+ _expect_any(#function, #parameter, __FILE__, __LINE__, count)
146
+
147
+ /* Determine whether a function parameter is correct. This ensures the next
148
+ * value queued by one of the expect_*() macros matches the specified variable.
149
+ */
150
+ #define check_expected(parameter) \
151
+ _check_expected(__func__, #parameter, __FILE__, __LINE__, (void*)parameter)
152
+
153
+ // Assert that the given expression is true.
154
+ #define assert_true(c) _assert_true((int)(c), #c, __FILE__, __LINE__)
155
+ // Assert that the given expression is false.
156
+ #define assert_false(c) _assert_true(!((int)(c)), #c, __FILE__, __LINE__)
157
+
158
+ // Assert that the two given integers are equal, otherwise fail.
159
+ #define assert_int_equal(a, b) _assert_int_equal(a, b, __FILE__, __LINE__)
160
+ // Assert that the two given integers are not equal, otherwise fail.
161
+ #define assert_int_not_equal(a, b) \
162
+ _assert_int_not_equal(a, b, __FILE__, __LINE__)
163
+
164
+ // Assert that the two given strings are equal, otherwise fail.
165
+ #define assert_string_equal(a, b) \
166
+ _assert_string_equal((const char*)a, (const char*)b, __FILE__, __LINE__)
167
+ // Assert that the two given strings are not equal, otherwise fail.
168
+ #define assert_string_not_equal(a, b) \
169
+ _assert_string_not_equal((const char*)a, (const char*)b, __FILE__, \
170
+ __LINE__)
171
+
172
+ // Assert that the two given areas of memory are equal, otherwise fail.
173
+ #define assert_memory_equal(a, b, size) \
174
+ _assert_memory_equal((const char*)a, (const char*)b, size, __FILE__, \
175
+ __LINE__)
176
+ // Assert that the two given areas of memory are not equal, otherwise fail.
177
+ #define assert_memory_not_equal(a, b, size) \
178
+ _assert_memory_not_equal((const char*)a, (const char*)b, size, __FILE__, \
179
+ __LINE__)
180
+
181
+ // Assert that the specified value is >= minimum and <= maximum.
182
+ #define assert_in_range(value, minimum, maximum) \
183
+ _assert_in_range((int)value, (int)minimum, (int)maximum, __FILE__, \
184
+ __LINE__)
185
+ // Assert that the specified value is < minumum or > maximum
186
+ #define assert_not_in_range(value, minimum, maximum) \
187
+ _assert_not_in_range((int)value, (int)minimum, (int)maximum, __FILE__, \
188
+ __LINE__)
189
+
190
+ // Assert that the specified value is within a set.
191
+ #define assert_in_set(value, values, number_of_values) \
192
+ _assert_in_set(value, values, number_of_values, __FILE__, __LINE__)
193
+ // Assert that the specified value is not within a set.
194
+ #define assert_not_in_set(value, values, number_of_values) \
195
+ _assert_not_in_set(value, values, number_of_values, __FILE__, __LINE__)
196
+
197
+
198
+ // Forces the test to fail immediately and quit.
199
+ #define fail() _fail(__FILE__, __LINE__)
200
+
201
+ // Generic method to kick off testing
202
+ #define run_test(f) _run_test(#f, f, NULL, UNIT_TEST_FUNCTION_TYPE_TEST, NULL)
203
+
204
+ // Initializes a UnitTest structure.
205
+ #define unit_test(f) { #f, f, UNIT_TEST_FUNCTION_TYPE_TEST }
206
+ #define unit_test_setup(test, setup) \
207
+ { #test "_" #setup, setup, UNIT_TEST_FUNCTION_TYPE_SETUP }
208
+ #define unit_test_teardown(test, teardown) \
209
+ { #test "_" #teardown, teardown, UNIT_TEST_FUNCTION_TYPE_TEARDOWN }
210
+
211
+ /* Initialize an array of UnitTest structures with a setup function for a test
212
+ * and a teardown function. Either setup or teardown can be NULL.
213
+ */
214
+ #define unit_test_setup_teardown(test, setup, teardown) \
215
+ unit_test_setup(test, setup), \
216
+ unit_test(test), \
217
+ unit_test_teardown(test, teardown)
218
+
219
+ /*
220
+ * Run tests specified by an array of UnitTest structures. The following
221
+ * example illustrates this macro's use with the unit_test macro.
222
+ *
223
+ * void Test0();
224
+ * void Test1();
225
+ *
226
+ * int main(int argc, char* argv[]) {
227
+ * const UnitTest tests[] = {
228
+ * unit_test(Test0);
229
+ * unit_test(Test1);
230
+ * };
231
+ * return run_tests(tests);
232
+ * }
233
+ */
234
+ #define run_tests(tests) _run_tests(tests, sizeof(tests) / sizeof(tests)[0])
235
+
236
+ // Dynamic allocators
237
+ #define test_malloc(size) _test_malloc(size, __FILE__, __LINE__)
238
+ #define test_calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__)
239
+ #define test_free(ptr) _test_free(ptr, __FILE__, __LINE__)
240
+
241
+ // Redirect malloc, calloc and free to the unit test allocators.
242
+ #if UNIT_TESTING
243
+ #define malloc test_malloc
244
+ #define calloc test_calloc
245
+ #define free test_free
246
+ #endif // UNIT_TESTING
247
+
248
+ /*
249
+ * Ensure mock_assert() is called. If mock_assert() is called the assert
250
+ * expression string is returned.
251
+ * For example:
252
+ *
253
+ * #define assert mock_assert
254
+ *
255
+ * void showmessage(const char *message) {
256
+ * assert(message);
257
+ * }
258
+ *
259
+ * int main(int argc, const char* argv[]) {
260
+ * expect_assert_failure(show_message(NULL));
261
+ * printf("succeeded\n");
262
+ * return 0;
263
+ * }
264
+ */
265
+ #define expect_assert_failure(function_call) \
266
+ { \
267
+ const char* expression = (const char*)setjmp(global_expect_assert_env); \
268
+ global_expecting_assert = 1; \
269
+ if (expression) { \
270
+ print_message("Expected assertion %s occurred\n", expression); \
271
+ global_expecting_assert = 0; \
272
+ } else { \
273
+ function_call ; \
274
+ global_expecting_assert = 0; \
275
+ print_error("Expected assert in %s\n", #function_call); \
276
+ _fail(__FILE__, __LINE__); \
277
+ } \
278
+ }
279
+
280
+ // Function prototype for setup, test and teardown functions.
281
+ typedef void (*UnitTestFunction)(void **state);
282
+
283
+ // Function that determines whether a function parameter value is correct.
284
+ typedef int (*CheckParameterValue)(const void *value, void *check_value_data);
285
+
286
+ // Type of the unit test function.
287
+ typedef enum UnitTestFunctionType {
288
+ UNIT_TEST_FUNCTION_TYPE_TEST = 0,
289
+ UNIT_TEST_FUNCTION_TYPE_SETUP,
290
+ UNIT_TEST_FUNCTION_TYPE_TEARDOWN,
291
+ } UnitTestFunctionType;
292
+
293
+ /* Stores a unit test function with its name and type.
294
+ * NOTE: Every setup function must be paired with a teardown function. It's
295
+ * possible to specify NULL function pointers.
296
+ */
297
+ typedef struct UnitTest {
298
+ const char* name;
299
+ UnitTestFunction function;
300
+ UnitTestFunctionType function_type;
301
+ } UnitTest;
302
+
303
+
304
+ // Location within some source code.
305
+ typedef struct SourceLocation {
306
+ const char* file;
307
+ int line;
308
+ } SourceLocation;
309
+
310
+ // Event that's called to check a parameter value.
311
+ typedef struct CheckParameterEvent {
312
+ SourceLocation location;
313
+ const char *parameter_name;
314
+ CheckParameterValue check_value;
315
+ void *check_value_data;
316
+ } CheckParameterEvent;
317
+
318
+ // Used by expect_assert_failure() and mock_assert().
319
+ extern int global_expecting_assert;
320
+ extern jmp_buf global_expect_assert_env;
321
+
322
+ // Retrieves a value for the given function, as set by "will_return".
323
+ void* _mock(const char * const function, const char* const file,
324
+ const int line);
325
+
326
+ void _expect_check(
327
+ const char* const function, const char* const parameter,
328
+ const char* const file, const int line,
329
+ const CheckParameterValue check_function, void * const check_data,
330
+ CheckParameterEvent * const event, const int count);
331
+
332
+ void _expect_in_set(
333
+ const char* const function, const char* const parameter,
334
+ const char* const file, const int line, const void *values[],
335
+ const size_t number_of_values, const int count);
336
+ void _expect_not_in_set(
337
+ const char* const function, const char* const parameter,
338
+ const char* const file, const int line, const void *values[],
339
+ const size_t number_of_values, const int count);
340
+
341
+ void _expect_in_range(
342
+ const char* const function, const char* const parameter,
343
+ const char* const file, const int line,
344
+ const int minimum, const int maximum, const int count);
345
+ void _expect_not_in_range(
346
+ const char* const function, const char* const parameter,
347
+ const char* const file, const int line,
348
+ const int minimum, const int maximum, const int count);
349
+ void _expect_value(
350
+ const char* const function, const char* const parameter,
351
+ const char* const file, const int line, const void* const value,
352
+ const int count);
353
+ void _expect_not_value(
354
+ const char* const function, const char* const parameter,
355
+ const char* const file, const int line, const void* const value,
356
+ const int count);
357
+ void _expect_string(
358
+ const char* const function, const char* const parameter,
359
+ const char* const file, const int line, const char* string,
360
+ const int count);
361
+ void _expect_not_string(
362
+ const char* const function, const char* const parameter,
363
+ const char* const file, const int line, const char* string,
364
+ const int count);
365
+ void _expect_memory(
366
+ const char* const function, const char* const parameter,
367
+ const char* const file, const int line, const void* const memory,
368
+ const size_t size, const int count);
369
+ void _expect_not_memory(
370
+ const char* const function, const char* const parameter,
371
+ const char* const file, const int line, const void* const memory,
372
+ const size_t size, const int count);
373
+ void _expect_any(
374
+ const char* const function, const char* const parameter,
375
+ const char* const file, const int line, const int count);
376
+
377
+ void _check_expected(
378
+ const char * const function_name, const char * const parameter_name,
379
+ const char* file, const int line, const void* value);
380
+
381
+ // Can be used to replace assert in tested code so that in conjuction with
382
+ // check_assert() it's possible to determine whether an assert condition has
383
+ // failed without stopping a test.
384
+ void mock_assert(const int result, const char* const expression,
385
+ const char * const file, const int line);
386
+
387
+ void _will_return(const char * const function_name, const char * const file,
388
+ const int line, const void* const value, const int count);
389
+ void _assert_true(const int result, const char* const expression,
390
+ const char * const file, const int line);
391
+ void _assert_int_equal(const int a, const int b, const char * const file,
392
+ const int line);
393
+ void _assert_int_not_equal(const int a, const int b, const char * const file,
394
+ const int line);
395
+ void _assert_string_equal(const char * const a, const char * const b,
396
+ const char * const file, const int line);
397
+ void _assert_string_not_equal(const char * const a, const char * const b,
398
+ const char *file, const int line);
399
+ void _assert_memory_equal(const void * const a, const void * const b,
400
+ const size_t size, const char* const file,
401
+ const int line);
402
+ void _assert_memory_not_equal(const void * const a, const void * const b,
403
+ const size_t size, const char* const file,
404
+ const int line);
405
+ void _assert_in_range(const int value, const int minimum, const int maximum,
406
+ const char* const file, const int line);
407
+ void _assert_not_in_range(const int value, const int minimum,
408
+ const int maximum, const char* const file,
409
+ const int line);
410
+ void _assert_in_set(const void * const value, const void *values[],
411
+ const size_t number_of_values, const char* const file,
412
+ const int line);
413
+ void _assert_not_in_set(const void * const value, const void *values[],
414
+ const size_t number_of_values, const char* const file,
415
+ const int line);
416
+
417
+ void* _test_malloc(const size_t size, const char* file, const int line);
418
+ void* _test_calloc(const size_t number_of_elements, const size_t size,
419
+ const char* file, const int line);
420
+ void _test_free(void* const ptr, const char* file, const int line);
421
+
422
+ void _fail(const char * const file, const int line);
423
+ int _run_test(
424
+ const char * const function_name, const UnitTestFunction Function,
425
+ void ** const state, const UnitTestFunctionType function_type,
426
+ const void* const heap_check_point);
427
+ int _run_tests(const UnitTest * const tests, const size_t number_of_tests);
428
+
429
+ // Standard output and error print methods.
430
+ void print_message(const char* const format, ...);
431
+ void print_error(const char* const format, ...);
432
+ void vprint_message(const char* const format, va_list args);
433
+ void vprint_error(const char* const format, va_list args);
434
+
435
+ #endif // CMOCKERY_H_
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>English</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>cmockery</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>com.yourcompany.cmockery</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>cmockery</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>FMWK</string>
17
+ <key>CFBundleShortVersionString</key>
18
+ <string>1.0</string>
19
+ <key>CFBundleSignature</key>
20
+ <string>????</string>
21
+ <key>CFBundleVersion</key>
22
+ <string>1</string>
23
+ </dict>
24
+ </plist>
@@ -10,7 +10,11 @@
10
10
  #include <stdarg.h>
11
11
  #include <stddef.h>
12
12
  #include <setjmp.h>
13
+ #if XCODE
14
+ #include <cmockery/cmockery.h>
15
+ #else
13
16
  #include <cmockery.h>
17
+ #endif
14
18
 
15
19
  #include <assert.h>
16
20
  #include <stdio.h>
@@ -34,13 +38,15 @@ extern int compare_by_version(const void *, const void *);
34
38
  static char *unsorted[] = {
35
39
  "1.0.9", "1.0.10", "1.10.1",
36
40
  "yui3-999", "2.0", "1.9.1",
37
- "yui3-990", "3.1.4.2", "1.0.9a",
41
+ "yui3-990", "3.1.4.2", "1.0.9a",
42
+ "1.0.9b", "1.0.9aa",
38
43
  };
39
44
 
40
45
  static char *expected_sorted[] = {
41
- "1.0.9", "1.0.9a", "1.0.10",
42
- "1.9.1", "1.10.1", "2.0",
43
- "3.1.4.2", "yui3-990", "yui3-999",
46
+ "1.0.9", "1.0.9a", "1.0.9aa",
47
+ "1.0.9b", "1.0.10", "1.9.1",
48
+ "1.10.1", "2.0", "3.1.4.2",
49
+ "yui3-990", "yui3-999",
44
50
  };
45
51
 
46
52
  static char *benchmark_list[] = { "yui3-571", "yui3-309", "yui3-1405", "yui3-1537", "yui3-440", "yui3-572", "yui3-1406", "yui3-1538", "yui3-441", "yui3-573", "yui3-1407", "yui3-1539", "yui3-310", "yui3-442", "yui3-574", "yui3-1408", "yui3-311", "yui3-443", "yui3-575", "yui3-1409", "yui3-312", "yui3-444", "yui3-576", "yui3-1540", "yui3-313", "yui3-445", "yui3-577", "yui3-1541", "yui3-314", "yui3-446", "yui3-1410", "yui3-578", "yui3-1542", "yui3-315", "yui3-447", "yui3-1411", "yui3-579", "yui3-1543", "3.0.0", "yui3-316", "yui3-448", "yui3-1412", "yui3-1544", "yui3-317", "yui3-449", "yui3-1413", "yui3-1545", "yui3-318", "yui3-1414", "yui3-1546", "yui3-580", "yui3-319", "yui3-1415", "yui3-1547", "yui3-581", "yui3-1416", "yui3-1548", "yui3-450", "yui3-582", "yui3-1417", "yui3-1549", "yui3-451", "yui3-583", "yui3-1418", "yui3-320", "yui3-452", "yui3-584", "yui3-1419", "yui3-321", "yui3-453", "yui3-585", "yui3-322", "yui3-454", "yui3-586", "yui3-1550", "yui3-323", "yui3-455", "yui3-587", "yui3-1551", "yui3-324", "yui3-456", "yui3-1420", "yui3-588", "yui3-1552", "yui3-325", "yui3-457", "yui3-1421", "yui3-589", "yui3-1553", "yui3-326", "yui3-458", "yui3-1422", "yui3-1554", "yui3-327", "yui3-459", "yui3-1423", "yui3-1555", "yui3-590", "yui3-328", "yui3-1424", "yui3-1556", "yui3-591", "yui3-329", "yui3-1425", "yui3-1557", "yui3-460", "yui3-592", "yui3-1426", "yui3-1558", "yui3-461", "yui3-593", "yui3-1427", "yui3-1559", "yui3-330", "yui3-462", "yui3-594", "yui3-1428", "yui3-331", "yui3-463", "yui3-595", "yui3-1429", "yui3-332", "yui3-464", "yui3-596", "yui3-1560", "yui3-333", "yui3-465", "yui3-597", "yui3-1561", "yui3-334", "yui3-466", "yui3-1430", "yui3-598", "yui3-1562", "yui3-335", "yui3-467", "yui3-1431", "yui3-599", "yui3-1563", "yui3-336", "yui3-1300", "yui3-468", "yui3-1432", "yui3-1564", "yui3-337", "yui3-1301", "yui3-469", "yui3-1433", "yui3-338", "yui3-1302", "yui3-1434", "yui3-339", "yui3-1303", "yui3-1435", "yui3-470", "yui3-1304", "yui3-1436", "yui3-471", "yui3-1305", "yui3-1437", "yui3-340", "yui3-472", "yui3-1306", "yui3-1438", "yui3-341", "yui3-473", "yui3-1307", "yui3-1439", "yui3-342", "yui3-474", "yui3-1308", "yui3-475", "yui3-1309", "yui3-343", "yui3-476", "yui3-1440", "yui3-344", "yui3-477", "yui3-1441", "yui3-345", "yui3-478", "yui3-1442", "yui3-346", "yui3-1310", "yui3-479", "yui3-1443", "yui3-900", "yui3-347", "yui3-1311", "yui3-1444", "yui3-901", "yui3-348", "yui3-1312", "yui3-1445", "yui3-902", "yui3-349", "yui3-1313", "yui3-1446", "yui3-903", "yui3-480", "yui3-1314", "yui3-1447", "yui3-904", "yui3-481", "yui3-1315", "yui3-1448", "yui3-905", "yui3-350", "yui3-482", "yui3-1316", "yui3-1449", "yui3-906", "yui3-351", "yui3-483", "yui3-1317", "yui3-907", "yui3-352", "yui3-484", "yui3-1318", "yui3-908", "yui3-353", "yui3-485", "yui3-1319", "yui3-909", "yui3-354", "yui3-486", "yui3-1450", "yui3-355", "yui3-487", "yui3-1451", "yui3-356", "yui3-1320", "yui3-488", "yui3-1452", "yui3-910", "yui3-357", "yui3-1321", "yui3-489", "yui3-1453", "yui3-911", "yui3-358", "yui3-1322", "yui3-1454", "yui3-912", "yui3-359", "yui3-1323", "yui3-1455", "yui3-490", "yui3-1324", "yui3-1456", "yui3-913", "yui3-491", "yui3-1325", "yui3-1457", "yui3-914", "yui3-360", "yui3-492", "yui3-1326", "yui3-1458", "yui3-915", "yui3-361", "yui3-493", "yui3-1327", "3.0.0pr2", "yui3-1459", "yui3-916", "yui3-362", "yui3-494", "yui3-1328", "yui3-917", "yui3-363", "yui3-495", "yui3-1329", "yui3-918", "yui3-364", "yui3-496", "yui3-1460", "yui3-919", "yui3-365", "yui3-497", "yui3-1461", "yui3-366", "yui3-1330", "yui3-498", "yui3-1462", "yui3-367", "yui3-1331", "yui3-499", "yui3-1463", "yui3-920", "yui3-1200", "yui3-368", "yui3-1332", "yui3-1464", "yui3-921", "yui3-1201", "yui3-369", "yui3-1333", "yui3-1465", "yui3-922", "yui3-1202", "yui3-1334", "yui3-1466", "yui3-923", "yui3-1203", "yui3-1335", "yui3-1467", "yui3-924", "yui3-1204", "yui3-1336", "yui3-1468", "yui3-925", "yui3-370", "yui3-1205", "yui3-1337", "yui3-1469", "yui3-926", "yui3-371", "yui3-1206", "yui3-1338", "yui3-927", "yui3-372", "yui3-1207", "yui3-1339", "yui3-928", "yui3-373", "yui3-1208", "yui3-929", "yui3-374", "yui3-1470", "yui3-1209", "yui3-375", "yui3-1471", "yui3-376", "yui3-1340", "yui3-1472", "yui3-930", "yui3-377", "yui3-1341", "yui3-1473", "yui3-931", "yui3-1210", "yui3-378", "yui3-1342", "yui3-1474", "yui3-800", "yui3-932", "yui3-1211", "yui3-379", "yui3-1343", "yui3-1475", "yui3-801", "yui3-933", "yui3-1212", "yui3-1344", "yui3-1476", "yui3-802", "yui3-934", "yui3-1213", "yui3-1345", "yui3-1477", "yui3-803", "yui3-935", "yui3-380", "yui3-1214", "yui3-1346", "yui3-1478", "yui3-804", "yui3-936", "yui3-381", "yui3-1215", "yui3-1347", "yui3-1479", "yui3-805", "yui3-937", "yui3-382", "yui3-1216", "yui3-1348", "yui3-806", "yui3-938", "yui3-383", "yui3-1349", "yui3-807", "yui3-939", "yui3-384", "yui3-1480", "yui3-1218", "yui3-808", "yui3-385", "yui3-1481", "yui3-1219", "yui3-809", "yui3-254", "yui3-386", "yui3-1350", "yui3-1482", "yui3-255", "yui3-387", "yui3-1351", "yui3-1483", "yui3-940", "yui3-256", "yui3-1220", "yui3-388", "yui3-1352", "yui3-1484", "yui3-941", "yui3-257", "yui3-1221", "yui3-389", "yui3-1353", "yui3-1485", "yui3-810", "yui3-942", "yui3-258", "yui3-1222", "yui3-1354", "yui3-1486", "yui3-811", "yui3-943", "yui3-259", "yui3-1223", "yui3-1355", "yui3-1487", "yui3-812", "yui3-944", "yui3-1224", "yui3-1356", "yui3-1488", "yui3-813", "yui3-945", "yui3-390", "yui3-1225", "yui3-1357", "yui3-1489", "yui3-814", "yui3-946", "yui3-391", "yui3-1226", "yui3-1358", "yui3-815", "yui3-947", "yui3-260", "yui3-392", "yui3-1227", "yui3-1359", "yui3-816", "yui3-948", "yui3-261", "yui3-393", "yui3-1490", "yui3-1228", "yui3-817", "yui3-949", "yui3-262", "yui3-394", "yui3-1491", "yui3-1229", "yui3-818", "yui3-263", "yui3-395", "yui3-1492", "yui3-819", "yui3-264", "yui3-396", "yui3-1360", "yui3-1493", "yui3-950", "yui3-265", "yui3-397", "yui3-1361", "yui3-1494", "yui3-951", "yui3-266", "yui3-1230", "yui3-398", "yui3-1362", "yui3-1495", "yui3-820", "yui3-952", "yui3-267", "yui3-1231", "yui3-399", "yui3-1363", "yui3-1496", "yui3-821", "yui3-953", "yui3-1100", "yui3-268", "yui3-1232", "yui3-1364", "yui3-1497", "yui3-822", "yui3-954", "yui3-1101", "yui3-269", "yui3-1233", "yui3-1365", "yui3-823", "yui3-955", "yui3-1102", "yui3-1234", "yui3-1366", "yui3-1498", "yui3-824", "yui3-956", "yui3-1103", "yui3-1235", "yui3-1367", "yui3-1499", "yui3-825", "yui3-957", "yui3-270", "yui3-1104", "yui3-1236", "yui3-1368", "yui3-826", "yui3-958", "yui3-271", "yui3-1105", "yui3-1237", "yui3-1369", "yui3-827", "yui3-959", "yui3-272", "yui3-1106", "yui3-1238", "yui3-828", "yui3-273", "yui3-1107", "yui3-1239", "yui3-829", "yui3-274", "yui3-1370", "yui3-1108", "yui3-275", "yui3-1371", "yui3-1109", "yui3-960", "yui3-276", "yui3-1240", "yui3-1372", "yui3-961", "yui3-277", "yui3-1241", "yui3-1373", "yui3-830", "yui3-962", "yui3-1110", "yui3-278", "yui3-1242", "yui3-1374", "yui3-831", "yui3-963", "yui3-1111", "yui3-279", "yui3-1243", "yui3-1375", "yui3-700", "yui3-832", "yui3-964", "yui3-1112", "yui3-1244", "yui3-1376", "yui3-701", "yui3-833", "yui3-965", "yui3-1113", "yui3-1245", "yui3-1377", "yui3-702", "yui3-834", "yui3-966", "yui3-280", "yui3-1114", "yui3-1246", "yui3-1378", "yui3-703", "yui3-835", "yui3-967", "yui3-281", "yui3-1115", "yui3-1247", "yui3-1379", "yui3-704", "yui3-836", "yui3-968", "yui3-282", "yui3-1116", "yui3-1248", "yui3-705", "yui3-837", "yui3-969", "yui3-283", "yui3-1117", "yui3-1249", "yui3-706", "yui3-838", "yui3-284", "yui3-1380", "yui3-1118", "yui3-707", "yui3-839", "yui3-285", "yui3-1381", "yui3-1119", "yui3-970", "yui3-708", "yui3-286", "yui3-1250", "yui3-1382", "yui3-971", "yui3-709", "yui3-287", "yui3-1251", "yui3-1383", "yui3-840", "yui3-972", "yui3-288", "yui3-1252", "yui3-1384", "yui3-841", "yui3-973", "yui3-1120", "yui3-289", "yui3-1253", "yui3-1385", "yui3-710", "yui3-842", "yui3-974", "yui3-1121", "yui3-1254", "yui3-1386", "yui3-711", "yui3-843", "yui3-975", "yui3-1122", "yui3-1255", "yui3-1387", "yui3-712", "yui3-844", "yui3-976", "yui3-1123", "yui3-1256", "yui3-1388", "yui3-713", "yui3-845", "yui3-977", "yui3-290", "yui3-1124", "yui3-1257", "yui3-1389", "yui3-714", "yui3-846", "yui3-978", "yui3-291", "yui3-1125", "yui3-1258", "yui3-715", "yui3-847", "yui3-979", "yui3-292", "yui3-1126", "yui3-1259", "yui3-716", "yui3-848", "yui3-293", "yui3-1127", "yui3-717", "yui3-849", "yui3-294", "yui3-1390", "yui3-1128", "yui3-980", "yui3-718", "yui3-295", "yui3-1391", "yui3-1129", "yui3-981", "yui3-719", "yui3-296", "yui3-1260", "yui3-1392", "yui3-850", "yui3-982", "yui3-297", "yui3-1261", "yui3-1393", "yui3-851", "yui3-983", "yui3-1130", "yui3-298", "yui3-1262", "yui3-1394", "yui3-720", "yui3-852", "yui3-984", "yui3-1131", "yui3-299", "yui3-1263", "yui3-1395", "yui3-721", "yui3-853", "yui3-985", "yui3-1000", "yui3-1132", "yui3-1264", "yui3-1396", "yui3-722", "yui3-854", "yui3-986", "yui3-1001", "yui3-1133", "yui3-1265", "yui3-1397", "yui3-855", "yui3-987", "yui3-1002", "yui3-1134", "yui3-1266", "yui3-1398", "yui3-723", "yui3-856", "yui3-988", "yui3-1003", "yui3-1135", "yui3-1267", "yui3-1399", "yui3-724", "yui3-857", "yui3-989", "yui3-1004", "yui3-1136", "yui3-1268", "yui3-725", "yui3-858", "yui3-1005", "yui3-1137", "yui3-1269", "yui3-726", "yui3-859", "yui3-1006", "yui3-1138", "yui3-727", "yui3-1007", "yui3-1139", "yui3-990", "yui3-728", "yui3-1270", "yui3-1008", "yui3-991", "yui3-729", "yui3-1271", "yui3-1009", "yui3-860", "yui3-992", "yui3-1140", "yui3-1272", "yui3-861", "yui3-993", "yui3-1141", "yui3-1273", "yui3-730", "yui3-862", "yui3-994", "yui3-1010", "yui3-1142", "yui3-1274", "yui3-731", "yui3-863", "yui3-995", "yui3-1011", "yui3-1143", "yui3-1275", "yui3-600", "yui3-732", "yui3-864", "yui3-996", "yui3-1012", "yui3-1144", "yui3-1276", "yui3-601", "yui3-733", "yui3-865", "yui3-997", "yui3-1277", "yui3-1145", "yui3-1013", "yui3-602", "yui3-734", "yui3-866", "yui3-998", "yui3-1278", "yui3-1146", "yui3-1014", "yui3-603", "yui3-735", "yui3-867", "yui3-999", "yui3-1279", "yui3-1147", "yui3-1015", "yui3-604", "yui3-736", "yui3-868", "yui3-1148", "yui3-1016", "yui3-605", "yui3-737", "yui3-869", "yui3-1149", "yui3-1017", "yui3-606", "yui3-738", "yui3-1280", "yui3-1018", "yui3-607", "yui3-739", "yui3-1281", "yui3-1019", "yui3-608", "yui3-870", "yui3-1282", "yui3-1150", "yui3-609", "yui3-871", "yui3-1283", "yui3-1151", "yui3-740", "yui3-872", "yui3-1284", "yui3-1152", "yui3-1020", "yui3-741", "yui3-873", "yui3-1285", "yui3-1153", "yui3-1021", "yui3-610", "yui3-742", "yui3-874", "yui3-1286", "yui3-1154", "yui3-1022", "yui3-611", "yui3-743", "yui3-875", "yui3-1287", "yui3-1155", "yui3-1023", "yui3-612", "yui3-744", "yui3-876", "yui3-1288", "yui3-1156", "yui3-1024", "yui3-613", "yui3-745", "yui3-877", "yui3-1289", "yui3-1157", "yui3-1025", "yui3-614", "yui3-746", "yui3-878", "yui3-1158", "yui3-1026", "yui3-615", "yui3-747", "yui3-879", "yui3-1159", "yui3-1027", "yui3-1290", "yui3-616", "yui3-748", "yui3-1028", "yui3-617", "yui3-749", "yui3-1029", "yui3-1291", "yui3-618", "yui3-880", "yui3-1292", "yui3-1160", "yui3-619", "yui3-881", "yui3-1293", "yui3-1161", "yui3-750", "yui3-882", "yui3-1294", "yui3-1162", "yui3-1030", "yui3-751", "yui3-883", "yui3-1295", "yui3-1163", "yui3-1031", "yui3-620", "yui3-752", "yui3-884", "yui3-1296", "yui3-1164", "yui3-1032", "yui3-621", "yui3-753", "yui3-885", "yui3-1297", "yui3-1165", "yui3-1033", "yui3-622", "yui3-754", "yui3-886", "yui3-1298", "yui3-1166", "yui3-1034", "yui3-623", "yui3-755", "yui3-887", "yui3-1299", "yui3-1167", "yui3-624", "yui3-756", "yui3-888", "yui3-1168", "yui3-625", "yui3-757", "yui3-889", "yui3-1169", "yui3-626", "yui3-758", "yui3-627", "yui3-759", "yui3-628", "yui3-890", "yui3-1170", "yui3-629", "yui3-891", "yui3-1171", "yui3-760", "yui3-892", "yui3-1172", "yui3-1040", "yui3-761", "yui3-893", "yui3-1173", "yui3-1041", "yui3-630", "yui3-762", "yui3-894", "yui3-1174", "yui3-1042", "yui3-631", "yui3-763", "yui3-895", "yui3-1175", "yui3-1043", "yui3-500", "yui3-632", "yui3-764", "yui3-896", "yui3-1176", "yui3-1044", "yui3-501", "yui3-633", "yui3-765", "yui3-897", "yui3-1177", "yui3-1045", "yui3-502", "yui3-634", "yui3-766", "yui3-898", "yui3-1178", "yui3-1046", "yui3-503", "yui3-635", "yui3-767", "yui3-899", "yui3-1179", "yui3-1047", "yui3-504", "yui3-636", "yui3-768", "yui3-1048", "yui3-505", "yui3-637", "yui3-769", "yui3-1049", "yui3-1180", "yui3-506", "yui3-638", "yui3-507", "yui3-639", "yui3-1181", "yui3-508", "yui3-770", "yui3-1182", "yui3-1050", "yui3-509", "yui3-771", "yui3-1183", "yui3-1051", "yui3-640", "yui3-772", "yui3-1184", "yui3-1052", "yui3-641", "yui3-773", "yui3-1185", "yui3-1053", "yui3-510", "yui3-642", "yui3-774", "yui3-1186", "yui3-1054", "yui3-511", "yui3-643", "yui3-775", "yui3-1187", "yui3-1055", "yui3-512", "yui3-644", "yui3-776", "yui3-1188", "yui3-1056", "yui3-513", "yui3-645", "yui3-777", "yui3-1189", "yui3-1057", "yui3-514", "yui3-646", "yui3-778", "yui3-1058", "yui3-515", "yui3-647", "yui3-779", "yui3-1059", "yui3-1190", "yui3-516", "yui3-648", "yui3-1191", "yui3-517", "yui3-649", "yui3-518", "yui3-780", "yui3-1192", "yui3-1060", "yui3-519", "yui3-781", "yui3-1193", "yui3-1061", "yui3-650", "yui3-782", "yui3-1194", "yui3-1062", "yui3-651", "yui3-783", "yui3-1195", "yui3-1063", "yui3-520", "yui3-652", "yui3-784", "yui3-1196", "yui3-1064", "yui3-521", "yui3-653", "yui3-785", "yui3-1197", "yui3-1065", "yui3-522", "yui3-654", "yui3-786", "yui3-1198", "yui3-1066", "yui3-523", "yui3-655", "yui3-787", "yui3-1199", "yui3-1067", "yui3-524", "yui3-656", "yui3-788", "yui3-1068", "yui3-525", "yui3-657", "yui3-789", "yui3-1069", "yui3-526", "yui3-658", "yui3-527", "yui3-659", "yui3-1070", "yui3-528", "yui3-790", "3.0.0beta1m1", "yui3-529", "yui3-791", "yui3-1071", "3.0.0beta1m2", "yui3-660", "yui3-792", "yui3-1072", "3.0.0beta1m3", "yui3-661", "yui3-793", "yui3-1073", "yui3-530", "yui3-662", "yui3-794", "yui3-1074", "yui3-531", "yui3-663", "yui3-795", "yui3-400", "yui3-1075", "yui3-532", "yui3-664", "yui3-796", "yui3-401", "yui3-1076", "yui3-533", "yui3-665", "yui3-797", "yui3-402", "yui3-1077", "yui3-534", "yui3-666", "yui3-798", "yui3-403", "yui3-1078", "yui3-535", "yui3-667", "yui3-799", "yui3-1500", "yui3-404", "yui3-1079", "yui3-536", "yui3-668", "yui3-1501", "yui3-405", "yui3-537", "yui3-669", "yui3-1502", "yui3-406", "yui3-1080", "yui3-538", "yui3-1503", "yui3-407", "yui3-1081", "yui3-539", "yui3-1504", "yui3-408", "yui3-670", "yui3-1505", "yui3-409", "yui3-1082", "yui3-671", "yui3-1506", "yui3-1083", "yui3-540", "yui3-672", "yui3-1507", "yui3-1084", "yui3-541", "yui3-673", "yui3-1508", "yui3-410", "yui3-1085", "yui3-542", "yui3-674", "yui3-1509", "yui3-411", "yui3-1086", "yui3-543", "yui3-675", "yui3-412", "yui3-1087", "yui3-544", "yui3-676", "yui3-413", "yui3-1088", "yui3-545", "yui3-677", "yui3-1510", "yui3-414", "yui3-1089", "yui3-546", "yui3-678", "yui3-1511", "yui3-415", "yui3-547", "yui3-679", "yui3-1090", "yui3-1512", "yui3-416", "yui3-548", "yui3-1091", "yui3-1513", "yui3-417", "yui3-549", "yui3-1092", "yui3-1514", "yui3-418", "yui3-680", "yui3-1515", "3.0.0b1", "yui3-419", "yui3-681", "yui3-1093", "yui3-1516", "yui3-550", "yui3-682", "yui3-1094", "yui3-1517", "yui3-551", "yui3-683", "yui3-1095", "yui3-1518", "yui3-420", "yui3-552", "yui3-684", "yui3-1096", "yui3-1519", "yui3-421", "yui3-553", "yui3-685", "yui3-1097", "yui3-422", "yui3-554", "yui3-686", "yui3-1098", "yui3-423", "yui3-555", "yui3-687", "yui3-1099", "yui3-1520", "yui3-424", "yui3-556", "yui3-688", "yui3-1521", "yui3-425", "yui3-557", "yui3-689", "yui3-1522", "yui3-426", "yui3-558", "yui3-1523", "yui3-427", "yui3-559", "yui3-1524", "yui3-428", "yui3-690", "yui3-1525", "yui3-429", "yui3-691", "yui3-1526", "yui3-560", "yui3-692", "yui3-1527", "yui3-561", "yui3-693", "yui3-430", "yui3-1528", "yui3-562", "yui3-694", "yui3-431", "yui3-1529", "yui3-563", "yui3-695", "yui3-432", "yui3-300", "yui3-564", "yui3-696", "yui3-433", "yui3-301", "yui3-565", "yui3-697", "yui3-1530", "yui3-434", "yui3-302", "yui3-566", "yui3-698", "yui3-1531", "yui3-435", "yui3-303", "yui3-567", "yui3-699", "yui3-1532", "yui3-1400", "yui3-436", "yui3-304", "yui3-568", "yui3-1533", "yui3-1401", "yui3-437", "yui3-305", "yui3-569", "yui3-1534", "yui3-1402", "yui3-438", "yui3-306", "yui3-1535", "yui3-1403", "yui3-439", "yui3-307", "yui3-1536", "yui3-1404", "yui3-308", "yui3-570" };
@@ -49,7 +55,7 @@ static char *benchmark_list[] = { "yui3-571", "yui3-309", "yui3-1405", "yui3-153
49
55
  void
50
56
  test_array_length(void **state)
51
57
  {
52
- assert(ARRAY_LENGH(unsorted) == 9);
58
+ assert(ARRAY_LENGH(unsorted) == 11);
53
59
  }
54
60
 
55
61
  void
@@ -11,33 +11,18 @@
11
11
  #include <stdio.h>
12
12
  #include <string.h>
13
13
  #include <ctype.h>
14
- #include <pcre.h>
15
14
  #include "version_sorter.h"
16
15
 
17
- static pcre *expr;
18
16
 
19
17
  static VersionSortingItem * version_sorting_item_init(const char *);
20
18
  static void version_sorting_item_free(VersionSortingItem *);
21
19
  static void version_sorting_item_add_piece(VersionSortingItem *, char *);
22
- static void setup_version_regex(void);
23
20
  static void parse_version_word(VersionSortingItem *);
24
21
  static void create_normalized_version(VersionSortingItem *, const int);
25
22
  static int compare_by_version(const void *, const void *);
23
+ static enum scan_state scan_state_get(const char);
26
24
 
27
25
 
28
- void
29
- setup_version_regex(void)
30
- {
31
- const char *pattern = "(\\d+|[a-zA-Z]+)";
32
- const char *errstr;
33
- int erroffset;
34
-
35
- if (!(expr = pcre_compile(pattern, 0, &errstr, &erroffset, 0))) {
36
- fprintf(stderr, "ERROR: %s: %s\n", pattern, errstr);
37
- exit(EXIT_FAILURE);
38
- }
39
- }
40
-
41
26
  VersionSortingItem *
42
27
  version_sorting_item_init(const char *original)
43
28
  {
@@ -96,44 +81,56 @@ version_sorting_item_add_piece(VersionSortingItem *vsi, char *str)
96
81
  }
97
82
  }
98
83
 
99
- void
100
- parse_version_word(VersionSortingItem *vsi)
84
+ enum scan_state
85
+ scan_state_get(const char c)
101
86
  {
102
- if (expr == NULL) {
103
- setup_version_regex();
104
- }
105
-
106
- int ovecsize = 0;
107
- if (pcre_fullinfo(expr, NULL, PCRE_INFO_CAPTURECOUNT, &ovecsize) != 0) {
108
- DIE("ERROR: Problem calling pcre_fullinfo")
109
- }
110
- ovecsize = (ovecsize + 1) * 3;
111
-
112
- int *ovector = calloc(ovecsize, sizeof(int));
113
- if (ovector == NULL) {
114
- DIE("ERROR: Not enough memory to allocate ovector")
87
+ if (isdigit(c)) {
88
+ return digit;
89
+ } else if (isalpha(c)) {
90
+ return alpha;
91
+ } else {
92
+ return other;
115
93
  }
116
94
 
117
- int offset = 0;
118
- int flags = 0;
95
+ }
96
+
97
+ void
98
+ parse_version_word(VersionSortingItem *vsi)
99
+ {
100
+ int start = 0, end = 0, size = 0;
101
+ char current_char, next_char;
119
102
  char *part;
103
+ enum scan_state current_state, next_state;
104
+
105
+ while ((current_char = vsi->original[start]) != '\0') {
106
+ current_state = scan_state_get(current_char);
107
+
108
+ if (current_state == other) {
109
+ start++;
110
+ end = start;
111
+ continue;
112
+ }
113
+
114
+ do {
115
+ end++;
116
+ next_char = vsi->original[end];
117
+ next_state = scan_state_get(next_char);
118
+ } while (next_char != '\0' && current_state == next_state);
120
119
 
121
- while (0 < pcre_exec(expr, 0, vsi->original, vsi->original_len, offset, flags, ovector, ovecsize)) {
120
+ size = end - start;
122
121
 
123
- part = malloc((vsi->original_len+1) * sizeof(char));
122
+ part = malloc((size+1) * sizeof(char));
124
123
  if (part == NULL) {
125
124
  DIE("ERROR: Not enough memory to allocate word")
126
125
  }
127
-
128
- snprintf(part, vsi->original_len+1, "%.*s", ovector[1]-ovector[0], vsi->original+ovector[0]);
129
-
126
+
127
+ memcpy(part, vsi->original+start, size);
128
+ part[size] = '\0';
129
+
130
130
  version_sorting_item_add_piece(vsi, part);
131
131
 
132
- offset = ovector[1];
133
- flags |= PCRE_NOTBOL;
132
+ start = end;
134
133
  }
135
-
136
- free(ovector);
137
134
  }
138
135
 
139
136
  void
@@ -150,15 +147,26 @@ create_normalized_version(VersionSortingItem *vsi, const int widest_len)
150
147
  pos = 0;
151
148
 
152
149
  for (cur = vsi->head; cur; cur = cur->next) {
153
- if (cur->len < widest_len) {
150
+
151
+ /* Left-Pad digits with a space */
152
+ if (cur->len < widest_len && isdigit(cur->str[0])) {
154
153
  for (i = 0; i < widest_len - cur->len; i++) {
155
154
  result[pos] = ' ';
156
155
  pos++;
157
- result[pos] = '\0';
158
156
  }
157
+ result[pos] = '\0';
159
158
  }
160
159
  strcat(result, cur->str);
161
160
  pos += cur->len;
161
+
162
+ /* Right-Pad words with a space */
163
+ if (cur->len < widest_len && isalpha(cur->str[0])) {
164
+ for (i = 0; i < widest_len - cur->len; i++) {
165
+ result[pos] = ' ';
166
+ pos++;
167
+ }
168
+ result[pos] = '\0';
169
+ }
162
170
  }
163
171
  vsi->normalized = result;
164
172
  vsi->widest_len = widest_len;
@@ -11,13 +11,20 @@
11
11
  #define _VERSION_SORTER_H
12
12
 
13
13
  #if UNIT_TESTING
14
+
14
15
  #define static
16
+
15
17
  #include <stdarg.h>
16
18
  #include <stddef.h>
17
19
  #include <setjmp.h>
20
+ #if XCODE
21
+ #include <cmockery/cmockery.h>
22
+ #else
18
23
  #include <cmockery.h>
19
24
  #endif
20
25
 
26
+ #endif
27
+
21
28
  #define DIE(msg) \
22
29
  fprintf(stderr, msg);\
23
30
  exit(EXIT_FAILURE);\
@@ -38,6 +45,10 @@ typedef struct _VersionPiece {
38
45
  struct _VersionPiece *next;
39
46
  } VersionPiece;
40
47
 
48
+ enum scan_state {
49
+ digit, alpha, other
50
+ };
51
+
41
52
  extern void version_sorter_sort(char **, size_t);
42
53
 
43
54
  #endif /* _VERSION_SORTER_H */
@@ -0,0 +1,3 @@
1
+ module VersionSorter
2
+ Version = '1.1.0'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: version_sorter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wanstrath
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-10-13 00:00:00 -07:00
13
+ date: 2009-10-14 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -28,11 +28,17 @@ files:
28
28
  - README.markdown
29
29
  - Rakefile
30
30
  - ext/version_sorter/extconf.rb
31
+ - ext/version_sorter/frameworks/cmockery.framework/Versions/A/Headers/cmockery.h
32
+ - ext/version_sorter/frameworks/cmockery.framework/Versions/A/Resources/English.lproj/InfoPlist.strings
33
+ - ext/version_sorter/frameworks/cmockery.framework/Versions/A/Resources/Info.plist
34
+ - ext/version_sorter/frameworks/cmockery.framework/Versions/A/cmockery
35
+ - ext/version_sorter/frameworks/cmockery.framework/cmockery
31
36
  - ext/version_sorter/rb_version_sorter.c
32
37
  - ext/version_sorter/test/main.c
33
38
  - ext/version_sorter/version_sorter.c
34
39
  - ext/version_sorter/version_sorter.h
35
40
  - ext/version_sorter/version_sorter.xcodeproj/project.pbxproj
41
+ - lib/version_sorter/version.rb
36
42
  - test/tags.rb
37
43
  - test/tags.txt
38
44
  - test/version_sorter_test.rb