-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions for lzstring compressing to URI components
- Loading branch information
Showing
6 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Generated by cpp11: do not edit by hand | ||
|
||
compressToEncodedURIComponent <- function(uncompressed8) { | ||
.Call(`_shinylive_compressToEncodedURIComponent`, uncompressed8) | ||
} | ||
|
||
decompressFromEncodedURIComponent <- function(compressed8) { | ||
.Call(`_shinylive_decompressFromEncodedURIComponent`, compressed8) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,31 @@ | ||
#include <cpp11.hpp> | ||
#include <codecvt> | ||
#include "lz-string.hpp" | ||
using namespace cpp11; | ||
|
||
[[cpp11::register]] | ||
void fun() {} | ||
std::string compressToEncodedURIComponent(std::string uncompressed8) { | ||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter_8_to_16; | ||
std::u16string uncompressed16 = converter_8_to_16.from_bytes(uncompressed8); | ||
|
||
auto compressed16 = lzstring::compressToEncodedURIComponent(uncompressed16); | ||
|
||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter_16_to_8; | ||
std::string compressed8 = converter_16_to_8.to_bytes(compressed16); | ||
|
||
return compressed8; | ||
} | ||
|
||
|
||
[[cpp11::register]] | ||
std::string decompressFromEncodedURIComponent(std::string compressed8) { | ||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter_8_to_16; | ||
std::u16string compressed16 = converter_8_to_16.from_bytes(compressed8); | ||
|
||
auto uncompressed16 = lzstring::decompressFromEncodedURIComponent(compressed16); | ||
|
||
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> converter_16_to_8; | ||
std::string uncompressed8 = converter_16_to_8.to_bytes(uncompressed16); | ||
|
||
return uncompressed8; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Generated by cpp11: do not edit by hand | ||
// clang-format off | ||
|
||
|
||
#include "cpp11/declarations.hpp" | ||
#include <R_ext/Visibility.h> | ||
|
||
// code.cpp | ||
std::string compressToEncodedURIComponent(std::string uncompressed8); | ||
extern "C" SEXP _shinylive_compressToEncodedURIComponent(SEXP uncompressed8) { | ||
BEGIN_CPP11 | ||
return cpp11::as_sexp(compressToEncodedURIComponent(cpp11::as_cpp<cpp11::decay_t<std::string>>(uncompressed8))); | ||
END_CPP11 | ||
} | ||
// code.cpp | ||
std::string decompressFromEncodedURIComponent(std::string compressed8); | ||
extern "C" SEXP _shinylive_decompressFromEncodedURIComponent(SEXP compressed8) { | ||
BEGIN_CPP11 | ||
return cpp11::as_sexp(decompressFromEncodedURIComponent(cpp11::as_cpp<cpp11::decay_t<std::string>>(compressed8))); | ||
END_CPP11 | ||
} | ||
|
||
extern "C" { | ||
static const R_CallMethodDef CallEntries[] = { | ||
{"_shinylive_compressToEncodedURIComponent", (DL_FUNC) &_shinylive_compressToEncodedURIComponent, 1}, | ||
{"_shinylive_decompressFromEncodedURIComponent", (DL_FUNC) &_shinylive_decompressFromEncodedURIComponent, 1}, | ||
{NULL, NULL, 0} | ||
}; | ||
} | ||
|
||
extern "C" attribute_visible void R_init_shinylive(DllInfo* dll){ | ||
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); | ||
R_useDynamicSymbols(dll, FALSE); | ||
R_forceSymbols(dll, TRUE); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters