Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
^cran-comments\.md$
^revdep$
^CRAN-SUBMISSION$
^\.Rproj\.user$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ local/quarto/*.html
local/quarto/*_files/
local/quarto/*.js
local/quarto/_extensions/
.Rproj.user
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Description: Exporting 'shiny' applications with 'shinylive' allows you to run t
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
BugReports: https://github.com/posit-dev/r-shinylive/issues
URL: https://posit-dev.github.io/r-shinylive/, https://github.com/posit-dev/r-shinylive
Imports:
Expand All @@ -33,3 +33,5 @@ Suggests:
Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Language: en-US
LinkingTo:
cpp11
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export(assets_remove)
export(assets_version)
export(export)
importFrom(rlang,is_interactive)
useDynLib(shinylive, .registration = TRUE)
9 changes: 9 additions & 0 deletions R/cpp11.R
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)
}
2 changes: 2 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#' @useDynLib shinylive, .registration = TRUE

assert_nzchar_string <- function(x) {
stopifnot(is.character(x) && nchar(x) > 0)
invisible(TRUE)
Expand Down
5 changes: 5 additions & 0 deletions shinylive.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
LineEndingConversion: Posix
Expand Down
3 changes: 3 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
*.so
*.dll
31 changes: 31 additions & 0 deletions src/code.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <cpp11.hpp>
#include <codecvt>
#include "lz-string.hpp"
using namespace cpp11;

[[cpp11::register]]
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;
}
35 changes: 35 additions & 0 deletions src/cpp11.cpp
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);
}
Loading