include language and encoding, follow the ndef specification for encoding text in ndef.
{
YKNDEF ndef;
memset(&ndef, 0, sizeof(YKNDEF));
- char text[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
- int rc = ykp_construct_ndef_text(&ndef, text);
+ char text[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+ int rc = ykp_construct_ndef_text(&ndef, text, "en", false);
assert(rc == 0);
assert(ndef.type == 'T');
- assert(strncmp(ndef.data, text, NDEF_DATA_SIZE) == 0);
+ assert(ndef.data[0] == 2);
+ assert(strncmp(ndef.data + 1, "en", 2) == 0);
+ assert(strncmp(ndef.data + 3, text, NDEF_DATA_SIZE - 3) == 0);
assert(ndef.len == NDEF_DATA_SIZE);
}
+void _test_other_lang_text()
+{
+ YKNDEF ndef;
+ memset(&ndef, 0, sizeof(YKNDEF));
+ char text[] = "aaaaaaaaaaaaaaa";
+ size_t text_len = strlen(text);
+ int rc = ykp_construct_ndef_text(&ndef, text, "sv-SE", true);
+ assert(rc == 0);
+ assert(ndef.type == 'T');
+ assert(ndef.data[0] == (0x80 & 5));
+ assert(strncmp(ndef.data + 1, "sv-SE", 5) == 0);
+ assert(strncmp(ndef.data + 6, text, text_len) == 0);
+ assert(ndef.len == text_len + 6);
+}
+
int main (void)
{
_test_https_uri();
_test_to_long_uri();
_test_exact_uri();
_test_exact_text();
+ _test_other_lang_text();
return 0;
}
}
/* Fill in the data and len parts of the YKNDEF struct based on supplied text. */
-int ykp_construct_ndef_text(YKNDEF *ndef, const char *text)
+int ykp_construct_ndef_text(YKNDEF *ndef, const char *text, const char *lang, bool isutf16)
{
size_t data_length = strlen(text);
- if(data_length > NDEF_DATA_SIZE) {
+ size_t lang_length = strlen(lang);
+ char status = lang_length;
+ if(isutf16) {
+ status &= 0x80;
+ }
+ if((data_length + lang_length + 1) > NDEF_DATA_SIZE) {
ykp_errno = YKP_EINVAL;
return 1;
}
- memcpy(ndef->data, text, data_length);
- ndef->len = data_length;
+ ndef->data[0] = status;
+ memcpy(ndef->data + 1, lang, lang_length);
+ memcpy(ndef->data + lang_length + 1, text, data_length);
+ ndef->len = data_length + lang_length + 1;
ndef->type = 'T';
return 0;
}
/* Functions for constructing the YKNDEF struct before writing it to a neo */
int ykp_construct_ndef_uri(YKNDEF *ndef, const char *uri);
-int ykp_construct_ndef_text(YKNDEF *ndef, const char *text);
+int ykp_construct_ndef_text(YKNDEF *ndef, const char *text, const char *lang, bool isutf16);
int ykp_set_access_code(YKP_CONFIG *cfg, unsigned char *access_code, size_t len);
int ykp_set_fixed(YKP_CONFIG *cfg, unsigned char *fixed, size_t len);
if(ndef_type == 'U') {
ykp_construct_ndef_uri(&ndef, ndef_string);
} else if(ndef_type == 'T') {
- ykp_construct_ndef_text(&ndef, ndef_string);
+ ykp_construct_ndef_text(&ndef, ndef_string, "en", false);
}
if(use_access_code) {
memcpy(ndef.curAccCode, access_code, ACC_CODE_SIZE);