X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2FAS_DCP.cpp;h=1abd0924e20b47e66aadc2ae83d327ada7485287;hb=cc05011a20424c6b855995b5965782582ca21c42;hp=10d5c666f451c436685f40abb42be1625892b0c9;hpb=1c20f520f0ac0d44c64cc53991f12c84a416b48f;p=asdcplib.git diff --git a/src/AS_DCP.cpp b/src/AS_DCP.cpp index 10d5c66..1abd092 100755 --- a/src/AS_DCP.cpp +++ b/src/AS_DCP.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2004-2006, John Hurst +Copyright (c) 2004-2014, John Hurst All rights reserved. Redistribution and use in source and binary forms, with or without @@ -35,9 +35,47 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. const char* ASDCP::Version() { - static char ver[16]; - snprintf(ver, 16, "%u.%u.%u", VERSION_MAJOR, VERSION_APIMINOR, VERSION_IMPMINOR); - return ver; + return PACKAGE_VERSION; +} + + + +//------------------------------------------------------------------------------------------ +// + +// Encodes a rational number as a string having a single delimiter character between +// numerator and denominator. Retuns the buffer pointer to allow convenient in-line use. +const char* +ASDCP::EncodeRational(const Rational& rational, char* str_buf, ui32_t buf_len, char delimiter) +{ + assert(str_buf); + snprintf(str_buf, buf_len, "%u%c%u", rational.Numerator, delimiter, rational.Denominator); + return str_buf; +} + +// Decodes a rational number havng a single non-digit delimiter character between +// the numerator and denominator. Returns false if the string does not contain +// the expected syntax. +bool +ASDCP::DecodeRational(const char* str_rational, Rational& rational) +{ + assert(str_rational); + rational.Numerator = strtol(str_rational, 0, 10); + + const char* p = str_rational; + while ( *p && isdigit(*p) ) + { + ++p; + } + + if ( p[0] == 0 || p[1] == 0 ) + { + return false; + } + + ++p; + rational.Denominator = strtol(p, 0, 10); + return true; }