982 |
982 |
int DateValue::read(const byte* buf, long len, ByteOrder /*byteOrder*/)
|
983 |
983 |
{
|
984 |
984 |
// Hard coded to read Iptc style dates
|
985 |
|
if (len != 8) {
|
|
985 |
if (len != 8 && len != 10) {
|
986 |
986 |
#ifndef SUPPRESS_WARNINGS
|
987 |
987 |
EXV_WARNING << Error(kerUnsupportedDateFormat) << "\n";
|
988 |
988 |
#endif
|
989 |
989 |
return 1;
|
990 |
990 |
}
|
991 |
991 |
// Make the buffer a 0 terminated C-string for sscanf
|
992 |
|
char b[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
993 |
|
std::memcpy(b, reinterpret_cast<const char*>(buf), 8);
|
994 |
|
int scanned = sscanf(b, "%4d%2d%2d",
|
|
992 |
char b[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
993 |
int scanned = 0;
|
|
994 |
if (len == 10) {
|
|
995 |
std::memcpy(b, reinterpret_cast<const char*>(buf), 10);
|
|
996 |
scanned = sscanf(b, "%4d-%2d-%2d",
|
995 |
997 |
&date_.year, &date_.month, &date_.day);
|
|
998 |
}
|
|
999 |
else { // len == 8
|
|
1000 |
std::memcpy(b, reinterpret_cast<const char*>(buf), 8);
|
|
1001 |
scanned = sscanf(b, "%4d%2d%2d",
|
|
1002 |
&date_.year, &date_.month, &date_.day);
|
|
1003 |
}
|
996 |
1004 |
if (scanned != 3) {
|
997 |
1005 |
#ifndef SUPPRESS_WARNINGS
|
998 |
1006 |
EXV_WARNING << Error(kerUnsupportedDateFormat) << "\n";
|
... | ... | |
1005 |
1013 |
int DateValue::read(const std::string& buf)
|
1006 |
1014 |
{
|
1007 |
1015 |
// Hard coded to read Iptc style dates
|
1008 |
|
if (buf.length() < 8) {
|
|
1016 |
if (buf.length() != 8 && buf.length() != 10) {
|
1009 |
1017 |
#ifndef SUPPRESS_WARNINGS
|
1010 |
1018 |
EXV_WARNING << Error(kerUnsupportedDateFormat) << "\n";
|
1011 |
1019 |
#endif
|
1012 |
1020 |
return 1;
|
1013 |
1021 |
}
|
1014 |
|
int scanned = sscanf(buf.c_str(), "%4d-%d-%d",
|
|
1022 |
int scanned = 0;
|
|
1023 |
if (buf.length() == 10) {
|
|
1024 |
scanned = sscanf(buf.c_str(), "%4d-%2d-%2d",
|
|
1025 |
&date_.year, &date_.month, &date_.day);
|
|
1026 |
}
|
|
1027 |
else { // len == 8
|
|
1028 |
scanned = sscanf(buf.c_str(), "%4d%2d%2d",
|
1015 |
1029 |
&date_.year, &date_.month, &date_.day);
|
|
1030 |
}
|
1016 |
1031 |
if (scanned != 3) {
|
1017 |
1032 |
#ifndef SUPPRESS_WARNINGS
|
1018 |
1033 |
EXV_WARNING << Error(kerUnsupportedDateFormat) << "\n";
|
... | ... | |
1118 |
1133 |
int TimeValue::read(const byte* buf, long len, ByteOrder /*byteOrder*/)
|
1119 |
1134 |
{
|
1120 |
1135 |
// Make the buffer a 0 terminated C-string for scanTime[36]
|
1121 |
|
char b[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
1122 |
|
std::memcpy(b, reinterpret_cast<const char*>(buf), (len < 12 ? len : 11));
|
|
1136 |
char b[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
1137 |
std::memcpy(b, reinterpret_cast<const char*>(buf), (len < 15 ? len : 14));
|
1123 |
1138 |
// Hard coded to read HHMMSS or Iptc style times
|
1124 |
1139 |
int rc = 1;
|
1125 |
1140 |
if (len == 6) {
|
1126 |
1141 |
// Try to read (non-standard) HHMMSS format
|
1127 |
1142 |
rc = scanTime3(b, "%2d%2d%2d");
|
1128 |
1143 |
}
|
1129 |
|
if (len == 11) {
|
|
1144 |
else if (len < 9) {
|
|
1145 |
rc = scanTime3(b, "%d:%d:%d");
|
|
1146 |
}
|
|
1147 |
else if (len == 11) {
|
1130 |
1148 |
rc = scanTime6(b, "%2d%2d%2d%1c%2d%2d");
|
1131 |
1149 |
}
|
|
1150 |
else if (len < 15) {
|
|
1151 |
rc = scanTime6(b, "%d:%d:%d%1c%d:%d");
|
|
1152 |
}
|
1132 |
1153 |
if (rc) {
|
1133 |
1154 |
rc = 1;
|
1134 |
1155 |
#ifndef SUPPRESS_WARNINGS
|
... | ... | |
1143 |
1164 |
// Hard coded to read H:M:S or Iptc style times
|
1144 |
1165 |
int rc = 1;
|
1145 |
1166 |
if (buf.length() < 9) {
|
1146 |
|
// Try to read (non-standard) H:M:S format
|
1147 |
|
rc = scanTime3(buf.c_str(), "%d:%d:%d");
|
|
1167 |
rc = scanTime3(buf.c_str(), "%2d%2d%2d");
|
|
1168 |
if (rc) {
|
|
1169 |
// Try to read (non-standard) H:M:S format
|
|
1170 |
rc = scanTime3(buf.c_str(), "%d:%d:%d");
|
|
1171 |
}
|
1148 |
1172 |
}
|
1149 |
1173 |
else {
|
1150 |
|
rc = scanTime6(buf.c_str(), "%d:%d:%d%1c%d:%d");
|
|
1174 |
rc = scanTime6(buf.c_str(), "%2d%2d%2d%1c%2d%2d");
|
|
1175 |
if (rc) {
|
|
1176 |
// Try to read (non-standard) H:M:S-H:M format
|
|
1177 |
rc = scanTime6(buf.c_str(), "%d:%d:%d%1c%d:%d");
|
|
1178 |
}
|
1151 |
1179 |
}
|
1152 |
1180 |
if (rc) {
|
1153 |
1181 |
rc = 1;
|
1154 |
|
-
|