nsid3v2.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "nsid3v2/nsid3v2.h"
  2. #include "nsid3v2/header.h"
  3. #include "nsid3v2/tag.h"
  4. #include <new>
  5. #include <strsafe.h>
  6. /*
  7. ================== Tag ==================
  8. = =
  9. =========================================
  10. */
  11. #if 0 // save for reference
  12. int NSID3v2_Frame_Text_SetUTF16(nsid3v2_frame_t f, const wchar_t *value)
  13. {
  14. ID3v2::Frame *frame = (ID3v2::Frame *)f;
  15. size_t len = wcslen(value);
  16. size_t bytes = len * 2 + 1; // leave 1 byte for encoding
  17. if (bytes < len) // woops, integer overflow
  18. return NErr_Error;
  19. size_t datalen;
  20. void *data;
  21. int ret = frame->NewData(bytes, &data, &datalen);
  22. if (ret == NErr_Success)
  23. {
  24. uint8_t *data8 = (uint8_t *)data;
  25. data8[0]=1; // set encoding to UTF-16
  26. memcpy(data8+1, value, len*2);
  27. }
  28. return ret;
  29. }
  30. int NSID3v2_Frame_UserText_SetUTF16(nsid3v2_frame_t f, const wchar_t *description, const wchar_t *value)
  31. {
  32. ID3v2::Frame *frame = (ID3v2::Frame *)f;
  33. size_t value_len = wcslen(value);
  34. size_t description_len = wcslen(description);
  35. size_t bytes = (value_len + description_len + 1) * 2 + 1; // leave 1 byte for encoding
  36. size_t datalen;
  37. void *data;
  38. int ret = frame->NewData(bytes, &data, &datalen);
  39. if (ret == NErr_Success)
  40. {
  41. uint8_t *data8 = (uint8_t *)data;
  42. data8[0]=1; // set encoding to UTF-16
  43. wcscpy((wchar_t *)(data8+1), description); // guaranteed to be room
  44. memcpy(data8+1+1+description_len*2, value, value_len*2);
  45. }
  46. return ret;
  47. }
  48. int NSID3v2_Frame_UserText_SetLatin(nsid3v2_frame_t f, const char *description, const char *value)
  49. {
  50. ID3v2::Frame *frame = (ID3v2::Frame *)f;
  51. size_t value_len = strlen(value);
  52. size_t description_len = strlen(description);
  53. size_t bytes = (value_len + description_len + 1) + 1; // leave 1 byte for encoding
  54. size_t datalen;
  55. void *data;
  56. int ret = frame->NewData(bytes, &data, &datalen);
  57. if (ret == NErr_Success)
  58. {
  59. uint8_t *data8 = (uint8_t *)data;
  60. data8[0]=0; // set encoding to ISO-8859-1
  61. strcpy((char *)(data8+1), description); // guaranteed to be room
  62. memcpy(data8+1+1+description_len, value, value_len);
  63. }
  64. return ret;
  65. }
  66. #endif