Skip to content

Commit

Permalink
chore: update coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Sep 6, 2023
1 parent 5a346e3 commit 4a9103f
Show file tree
Hide file tree
Showing 38 changed files with 2,618 additions and 2,782 deletions.
5 changes: 4 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
BasedOnStyle: LLVM

ColumnLimit: 120
UseTab: AlignWithSpaces
IndentWidth: 4
TabWidth: 4
...
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ indent_style = space
indent_size = 4

[*.{c,cpp,h,hpp}]
indent_size = 2
indent_style = tab

[*.{yml,yaml,m4,w32}]
indent_size = 2
Expand Down
14 changes: 14 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@
"build:clean": {
"script": "make clean"
},
"lint:all": {
"override": true,
"script": [
"./tools/clang-format.sh"
]
},
"lint:fix": {
"override": true,
"script": "./tools/clang-format.sh apply"
},
"lint:style": {
"override": true,
"script": "./tools/clang-format.sh"
},
"test:all": {
"override": true,
"script": [
Expand Down
40 changes: 19 additions & 21 deletions src/ecma402/calendar.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,33 @@
#include <unicode/uloc.h>

int ecma402_availableCanonicalCalendars(const char **values) {
UEnumeration *enumeration = NULL;
UErrorCode status = U_ZERO_ERROR;
const char *identifier;
int identifierLength, valuesCount = 0;
UEnumeration *enumeration = NULL;
UErrorCode status = U_ZERO_ERROR;
const char *identifier;
int identifierLength, valuesCount = 0;

enumeration =
ucal_getKeywordValuesForLocale(ICU_KEYWORD_CALENDAR, NULL, 0, &status);
enumeration = ucal_getKeywordValuesForLocale(ICU_KEYWORD_CALENDAR, NULL, 0, &status);

if (U_FAILURE(status)) {
return 0;
}
if (U_FAILURE(status)) {
return 0;
}

while ((identifier = uenum_next(enumeration, &identifierLength, &status))) {
const char *tmpIdentifier = NULL;
tmpIdentifier = uloc_toUnicodeLocaleType(ICU_KEYWORD_CALENDAR, identifier);
while ((identifier = uenum_next(enumeration, &identifierLength, &status))) {
const char *tmpIdentifier = NULL;
tmpIdentifier = uloc_toUnicodeLocaleType(ICU_KEYWORD_CALENDAR, identifier);

size_t tmpIdLength = strlen(tmpIdentifier);
values[valuesCount] = (const char *)malloc(tmpIdLength + 1);
memcpy((void *)values[valuesCount], tmpIdentifier, tmpIdLength + 1);
size_t tmpIdLength = strlen(tmpIdentifier);
values[valuesCount] = (const char *)malloc(tmpIdLength + 1);
memcpy((void *)values[valuesCount], tmpIdentifier, tmpIdLength + 1);

valuesCount++;
}
valuesCount++;
}

uenum_close(enumeration);
uenum_close(enumeration);

return ecma402_sortAndRemoveDuplicates((char **)values, valuesCount,
ecma402_strToLower);
return ecma402_sortAndRemoveDuplicates((char **)values, valuesCount, ecma402_strToLower);
}

int ecma402_calendarsOfLocale(ecma402_locale *locale, const char **values) {
return ecma402_keywordsOfLocale(locale, ICU_KEYWORD_CALENDAR, values);
return ecma402_keywordsOfLocale(locale, ICU_KEYWORD_CALENDAR, values);
}
14 changes: 7 additions & 7 deletions src/ecma402/calendar.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ extern "C" {
* @link https://tc39.es/proposal-intl-locale-info/#sec-week-info-of-locale
*/
typedef enum ecma402_dayOfWeek {
ECMA402_MONDAY = 1,
ECMA402_TUESDAY,
ECMA402_WEDNESDAY,
ECMA402_THURSDAY,
ECMA402_FRIDAY,
ECMA402_SATURDAY,
ECMA402_SUNDAY,
ECMA402_MONDAY = 1,
ECMA402_TUESDAY,
ECMA402_WEDNESDAY,
ECMA402_THURSDAY,
ECMA402_FRIDAY,
ECMA402_SATURDAY,
ECMA402_SUNDAY,
} ecma402_dayOfWeek;

/**
Expand Down
59 changes: 29 additions & 30 deletions src/ecma402/category.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,38 @@

#include <string.h>

int ecma402_supportedValuesForCategory(const char *category,
const char **values) {
if (strcmp(ECMA402_CATEGORY_CALENDAR, category) == 0) {
return ecma402_availableCanonicalCalendars(values);
} else if (strcmp(ECMA402_CATEGORY_COLLATION, category) == 0) {
return ecma402_availableCanonicalCollations(values);
} else if (strcmp(ECMA402_CATEGORY_CURRENCY, category) == 0) {
return ecma402_availableCanonicalCurrencies(values);
} else if (strcmp(ECMA402_CATEGORY_NUMBERING_SYSTEM, category) == 0) {
return ecma402_availableCanonicalNumberingSystems(values);
} else if (strcmp(ECMA402_CATEGORY_TIME_ZONE, category) == 0) {
return ecma402_availableCanonicalTimeZones(values);
} else if (strcmp(ECMA402_CATEGORY_UNIT, category) == 0) {
return ecma402_availableCanonicalUnits(values);
}
int ecma402_supportedValuesForCategory(const char *category, const char **values) {
if (strcmp(ECMA402_CATEGORY_CALENDAR, category) == 0) {
return ecma402_availableCanonicalCalendars(values);
} else if (strcmp(ECMA402_CATEGORY_COLLATION, category) == 0) {
return ecma402_availableCanonicalCollations(values);
} else if (strcmp(ECMA402_CATEGORY_CURRENCY, category) == 0) {
return ecma402_availableCanonicalCurrencies(values);
} else if (strcmp(ECMA402_CATEGORY_NUMBERING_SYSTEM, category) == 0) {
return ecma402_availableCanonicalNumberingSystems(values);
} else if (strcmp(ECMA402_CATEGORY_TIME_ZONE, category) == 0) {
return ecma402_availableCanonicalTimeZones(values);
} else if (strcmp(ECMA402_CATEGORY_UNIT, category) == 0) {
return ecma402_availableCanonicalUnits(values);
}

return 0;
return 0;
}

int ecma402_capacityForCategory(const char *category) {
if (strcmp(ECMA402_CATEGORY_CALENDAR, category) == 0) {
return ECMA402_CALENDAR_CAPACITY;
} else if (strcmp(ECMA402_CATEGORY_COLLATION, category) == 0) {
return ECMA402_COLLATION_CAPACITY;
} else if (strcmp(ECMA402_CATEGORY_CURRENCY, category) == 0) {
return ECMA402_CURRENCY_CAPACITY;
} else if (strcmp(ECMA402_CATEGORY_NUMBERING_SYSTEM, category) == 0) {
return ECMA402_NUMBERING_SYSTEM_CAPACITY;
} else if (strcmp(ECMA402_CATEGORY_TIME_ZONE, category) == 0) {
return ECMA402_TIME_ZONE_CAPACITY;
} else if (strcmp(ECMA402_CATEGORY_UNIT, category) == 0) {
return ECMA402_UNIT_CAPACITY;
}
if (strcmp(ECMA402_CATEGORY_CALENDAR, category) == 0) {
return ECMA402_CALENDAR_CAPACITY;
} else if (strcmp(ECMA402_CATEGORY_COLLATION, category) == 0) {
return ECMA402_COLLATION_CAPACITY;
} else if (strcmp(ECMA402_CATEGORY_CURRENCY, category) == 0) {
return ECMA402_CURRENCY_CAPACITY;
} else if (strcmp(ECMA402_CATEGORY_NUMBERING_SYSTEM, category) == 0) {
return ECMA402_NUMBERING_SYSTEM_CAPACITY;
} else if (strcmp(ECMA402_CATEGORY_TIME_ZONE, category) == 0) {
return ECMA402_TIME_ZONE_CAPACITY;
} else if (strcmp(ECMA402_CATEGORY_UNIT, category) == 0) {
return ECMA402_UNIT_CAPACITY;
}

return 0;
return 0;
}
3 changes: 1 addition & 2 deletions src/ecma402/category.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ extern "C" {
*
* @return The total count of the supported values returned for the category.
*/
int ecma402_supportedValuesForCategory(const char *category,
const char **values);
int ecma402_supportedValuesForCategory(const char *category, const char **values);

/**
* Returns the recommended const char ** capacity for the given category.
Expand Down
51 changes: 25 additions & 26 deletions src/ecma402/collation.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,40 @@
#include <unicode/uloc.h>

int ecma402_availableCanonicalCollations(const char **values) {
UEnumeration *enumeration = NULL;
UErrorCode status = U_ZERO_ERROR;
const char *identifier;
int identifierLength, valuesCount = 0;
UEnumeration *enumeration = NULL;
UErrorCode status = U_ZERO_ERROR;
const char *identifier;
int identifierLength, valuesCount = 0;

enumeration = ucol_getKeywordValues(ICU_KEYWORD_COLLATION, &status);
enumeration = ucol_getKeywordValues(ICU_KEYWORD_COLLATION, &status);

if (U_FAILURE(status)) {
return 0;
}
if (U_FAILURE(status)) {
return 0;
}

while ((identifier = uenum_next(enumeration, &identifierLength, &status))) {
const char *tmpIdentifier = NULL;
tmpIdentifier = uloc_toUnicodeLocaleType(ICU_KEYWORD_COLLATION, identifier);
while ((identifier = uenum_next(enumeration, &identifierLength, &status))) {
const char *tmpIdentifier = NULL;
tmpIdentifier = uloc_toUnicodeLocaleType(ICU_KEYWORD_COLLATION, identifier);

// According to ECMA-402, section 10.2.3, "the values 'standard' and
// 'search' must not be used as elements in any [collation] list."
if (strcasecmp(tmpIdentifier, ECMA402_COLLATION_STANDARD) == 0 ||
strcasecmp(tmpIdentifier, ECMA402_COLLATION_SEARCH) == 0) {
continue;
}
// According to ECMA-402, section 10.2.3, "the values 'standard' and
// 'search' must not be used as elements in any [collation] list."
if (strcasecmp(tmpIdentifier, ECMA402_COLLATION_STANDARD) == 0 ||
strcasecmp(tmpIdentifier, ECMA402_COLLATION_SEARCH) == 0) {
continue;
}

size_t tmpIdLength = strlen(tmpIdentifier);
values[valuesCount] = (const char *)malloc(tmpIdLength + 1);
memcpy((void *)values[valuesCount], tmpIdentifier, tmpIdLength + 1);
size_t tmpIdLength = strlen(tmpIdentifier);
values[valuesCount] = (const char *)malloc(tmpIdLength + 1);
memcpy((void *)values[valuesCount], tmpIdentifier, tmpIdLength + 1);

valuesCount++;
}
valuesCount++;
}

uenum_close(enumeration);
uenum_close(enumeration);

return ecma402_sortAndRemoveDuplicates((char **)values, valuesCount,
ecma402_strToLower);
return ecma402_sortAndRemoveDuplicates((char **)values, valuesCount, ecma402_strToLower);
}

int ecma402_collationsOfLocale(ecma402_locale *locale, const char **values) {
return ecma402_keywordsOfLocale(locale, ICU_KEYWORD_COLLATION, values);
return ecma402_keywordsOfLocale(locale, ICU_KEYWORD_COLLATION, values);
}
41 changes: 20 additions & 21 deletions src/ecma402/currency.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,35 @@
#include <unicode/uenum.h>

int ecma402_availableCanonicalCurrencies(const char **values) {
UEnumeration *enumeration = NULL;
UErrorCode status = U_ZERO_ERROR;
const char *identifier;
int identifierLength, valuesCount = 0;
UEnumeration *enumeration = NULL;
UErrorCode status = U_ZERO_ERROR;
const char *identifier;
int identifierLength, valuesCount = 0;

enumeration = ucurr_openISOCurrencies(UCURR_ALL, &status);
enumeration = ucurr_openISOCurrencies(UCURR_ALL, &status);

if (U_FAILURE(status)) {
return 0;
}
if (U_FAILURE(status)) {
return 0;
}

while ((identifier = uenum_next(enumeration, &identifierLength, &status))) {
values[valuesCount] = (const char *)malloc(identifierLength + 1);
memcpy((void *)values[valuesCount], identifier, identifierLength + 1);
while ((identifier = uenum_next(enumeration, &identifierLength, &status))) {
values[valuesCount] = (const char *)malloc(identifierLength + 1);
memcpy((void *)values[valuesCount], identifier, identifierLength + 1);

valuesCount++;
}
valuesCount++;
}

uenum_close(enumeration);
uenum_close(enumeration);

return ecma402_sortAndRemoveDuplicates((char **)values, valuesCount,
ecma402_strToUpper);
return ecma402_sortAndRemoveDuplicates((char **)values, valuesCount, ecma402_strToUpper);
}

int ecma402_currenciesOfLocale(ecma402_locale *locale, const char **values) {
int count = ecma402_keywordsOfLocale(locale, ICU_KEYWORD_CURRENCY, values);
int count = ecma402_keywordsOfLocale(locale, ICU_KEYWORD_CURRENCY, values);

for (int i = 0; i < count; i++) {
values[i] = ecma402_strToUpper((char *)values[i]);
}
for (int i = 0; i < count; i++) {
values[i] = ecma402_strToUpper((char *)values[i]);
}

return count;
return count;
}
Loading

0 comments on commit 4a9103f

Please sign in to comment.