Skip to content

Commit

Permalink
fixed the features for metadata reading for Mobi and AZW3
Browse files Browse the repository at this point in the history
  • Loading branch information
angelgarcia999 committed May 8, 2024
1 parent b437e2e commit d042c87
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Charcoal/Charcoal/AZW3.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "AZW3.h"
<<<<<<< HEAD
/*
=======
>>>>>>> ce8f777 (fixed the features for metadata reading for Mobi and AZW3)
#include <mobi.h>
#include <cstdio>
#include <iostream>
Expand Down Expand Up @@ -50,10 +53,15 @@ MOBIData* initAndLoadMobi(const std::string& filePath) {
}
book azw3::add(PWSTR path) {
<<<<<<< HEAD
// Convert PWSTR to std::wstring
std::wstring ws(path);
// Now convert std::wstring to std::string
std::string filePath = std::wstring_convert<std::codecvt_utf8<wchar_t>>().to_bytes(ws);
=======
wstring ws(path);
string filePath = wstring_to_utf8(ws);
>>>>>>> ce8f777 (fixed the features for metadata reading for Mobi and AZW3)
// Initialize and load MOBI file
MOBIData* mobiData = initAndLoadMobi(filePath);
Expand Down Expand Up @@ -82,7 +90,11 @@ book azw3::add(PWSTR path) {
book mobi::add(PWSTR path) {
std::wstring ws(path);
<<<<<<< HEAD
std::string filePath = std::wstring_convert<std::codecvt_utf8<wchar_t>>().to_bytes(ws);
=======
std::string filePath = wstring_to_utf8(ws);
>>>>>>> ce8f777 (fixed the features for metadata reading for Mobi and AZW3)
// Initialize and load MOBI file
MOBIData* mobiData = initAndLoadMobi(filePath);
Expand Down Expand Up @@ -157,5 +169,9 @@ bool extractContentFromMobi(const std::string& filePath, const std::string& outp
mobi_free(mobiData);
return true;
<<<<<<< HEAD
}
*/
*/
=======
}
>>>>>>> ce8f777 (fixed the features for metadata reading for Mobi and AZW3)
15 changes: 15 additions & 0 deletions Charcoal/Charcoal/AZW3.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
#pragma once
#include "Library.h"
<<<<<<< HEAD
=======
#include <Windows.h>
#include <string>

std::string wstring_to_utf8(const std::wstring& wstr) {
if (wstr.empty()) return std::string();

int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), nullptr, 0, nullptr, nullptr);
std::string strTo(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, nullptr, nullptr);
return strTo;
}

>>>>>>> ce8f777 (fixed the features for metadata reading for Mobi and AZW3)
class mobi : public Library
{
public:
Expand Down

0 comments on commit d042c87

Please sign in to comment.