Make iso8601_print() return a pointer to its output buffer. This breaks
the ABI.
This commit is contained in:
parent
d08f81a6cf
commit
f82859fa78
|
@ -43,12 +43,13 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
|
||||||
\param amt Number of bytes in \a str.
|
\param amt Number of bytes in \a str.
|
||||||
\param date Date to print.
|
\param date Date to print.
|
||||||
\param details Formatting details (may be 0).
|
\param details Formatting details (may be 0).
|
||||||
|
\returns Pointer to buffer (\a str).
|
||||||
|
|
||||||
Formats and prints an ISO8601 date, optionally using the details in \a details. Will always return
|
Formats and prints an ISO8601 date, optionally using the details in \a details. Will always return
|
||||||
a null-terminated result, even if that means truncating the output to fit the buffer.
|
a null-terminated result, even if that means truncating the output to fit the buffer.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
char* iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
||||||
const struct iso8601_details* details);
|
const struct iso8601_details* details);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ static const struct iso8601_details _default_details = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
char* iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
||||||
const struct iso8601_details* details)
|
const struct iso8601_details* details)
|
||||||
{
|
{
|
||||||
int y, m, d, ret = 0, extended;
|
int y, m, d, ret = 0, extended;
|
||||||
|
@ -38,12 +38,12 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
||||||
case iso8601_prec_year:
|
case iso8601_prec_year:
|
||||||
if(y < 0) snprintf(str, amt, "%05d", y);
|
if(y < 0) snprintf(str, amt, "%05d", y);
|
||||||
else snprintf(str, amt, "%04d", y);
|
else snprintf(str, amt, "%04d", y);
|
||||||
return;
|
return str;
|
||||||
|
|
||||||
case iso8601_prec_month:
|
case iso8601_prec_month:
|
||||||
if(y < 0) snprintf(str, amt, "%05d-%02d", y, m);
|
if(y < 0) snprintf(str, amt, "%05d-%02d", y, m);
|
||||||
else snprintf(str, amt, extended ? "%04d-%02d" : "%04d%02d", y, m);
|
else snprintf(str, amt, extended ? "%04d-%02d" : "%04d%02d", y, m);
|
||||||
return;
|
return str;
|
||||||
|
|
||||||
case iso8601_prec_day:
|
case iso8601_prec_day:
|
||||||
if(y < 0) ret = snprintf(str, amt, "%05d-%02d-%02d", y, m, d);
|
if(y < 0) ret = snprintf(str, amt, "%05d-%02d-%02d", y, m, d);
|
||||||
|
@ -61,7 +61,7 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
||||||
extended = y < 0 || y > 9999 || details->extended; // ISO year is different
|
extended = y < 0 || y > 9999 || details->extended; // ISO year is different
|
||||||
if(y < 0) snprintf(str, amt, "%05d-W%02d", y, m);
|
if(y < 0) snprintf(str, amt, "%05d-W%02d", y, m);
|
||||||
else snprintf(str, amt, extended ? "%04d-W%02d" : "%04dW%02d", y, m);
|
else snprintf(str, amt, extended ? "%04d-W%02d" : "%04dW%02d", y, m);
|
||||||
return;
|
return str;
|
||||||
|
|
||||||
case iso8601_prec_wday:
|
case iso8601_prec_wday:
|
||||||
iso8601_to_week(&y, &m, &d, &dttz);
|
iso8601_to_week(&y, &m, &d, &dttz);
|
||||||
|
@ -71,7 +71,7 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret < 1 || ret >= amt) return;
|
if(ret < 1 || ret >= amt) return str;
|
||||||
str += ret;
|
str += ret;
|
||||||
amt -= ret;
|
amt -= ret;
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
||||||
|
|
||||||
switch(details->time_prec) {
|
switch(details->time_prec) {
|
||||||
case iso8601_prec_none:
|
case iso8601_prec_none:
|
||||||
return;
|
return str;
|
||||||
|
|
||||||
case iso8601_prec_hour:
|
case iso8601_prec_hour:
|
||||||
ret = snprintf(str, amt, "T%02d", y);
|
ret = snprintf(str, amt, "T%02d", y);
|
||||||
|
@ -122,14 +122,14 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret < 1 || ret >= amt) return;
|
if(ret < 1 || ret >= amt) return str;
|
||||||
str += ret;
|
str += ret;
|
||||||
amt -= ret;
|
amt -= ret;
|
||||||
|
|
||||||
if(details->tz_sec) {
|
if(details->tz_sec) {
|
||||||
if(!--amt) {
|
if(!--amt) {
|
||||||
*str = 0;
|
*str = 0;
|
||||||
return;
|
return str;
|
||||||
}
|
}
|
||||||
if(details->tz_sec < 0) {
|
if(details->tz_sec < 0) {
|
||||||
*str++ = '-';
|
*str++ = '-';
|
||||||
|
|
Loading…
Reference in New Issue