Comments (7)
From the README:
You can create a single-header version of the library where all of the code is put into two files (simdutf.h and simdutf.cpp). We publish a zip archive containing these files, e.g., see https://github.com/simdutf/simdutf/releases/download/v3.2.2/singleheader.zip
There is a single header and a single source file.
We provide an example... here is a simplified version:
#include <iostream>
#include <memory>
#include "simdutf.cpp"
#include "simdutf.h"
int main(int , char *[]) {
const char *source = "1234";
// 4 == strlen(source)
bool validutf8 = simdutf::validate_utf8(source, 4);
if (validutf8) {
std::cout << "valid UTF-8" << std::endl;
} else {
std::cerr << "invalid UTF-8" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Also, I expect to be able to install both versions at the same time. But now the amalgamated file from the zip archive and include/simduft.h have the same name, so it's unclear how to differentiate them in CMAKE_INSTALL_INCLUDEDIR.
I am not sure what you mean by both at the same time. You can either use the single-header version, in which case you just copy simdutf.h
and simdutf.cpp
to your project. Or else, if you want to use simdutf
as an installed package of some sort, then you do so... Here is a CMake example...
cmake_minimum_required(VERSION 3.15)
project(test_simdutf_install VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(MSVC_VERSION GREATER 1910)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -permissive-")
endif()
find_package(simdutf REQUIRED)
file(WRITE main.cpp "
#include <iostream>
#include \"simdutf.h\"
int main(int argc, char *argv[]) {
const char * ascii = \"1234\";
bool validutf8 = simdutf::validate_utf8(ascii, 4);
if(validutf8) {
std::cout << \"valid UTF-8\" << std::endl;
} else {
std::cout << \"invalid UTF-8\" << std::endl;
return EXIT_FAILURE;
}
char16_t utf16_output[4];
// convert to UTF-16LE
size_t utf16words = simdutf::convert_utf8_to_utf16le(ascii, 4, utf16_output);
std::cout << \"wrote \" << utf16words << \" UTF-16 words.\" << std::endl;
// It wrote utf16words * sizeof(char16_t) bytes.
//
// convert it back:
char buffer[4];
size_t utf8words = simdutf::convert_utf16le_to_utf8(utf16_output, utf16words, buffer);
std::cout << \"wrote \" << utf8words << \" UTF-8 words.\" << std::endl;
return EXIT_SUCCESS;
}")
add_executable(repro main.cpp)
target_link_libraries(repro PUBLIC simdutf::simdutf)
from simdutf.
If you use the single-header release, then two files must be installed the header (there is just one) and the source file.
from simdutf.
From CMake, you can use simdutf as a dependency as follows...
cmake_minimum_required(VERSION 3.15)
project(simdutf_demo_install VERSION 0.1.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(
simdutf
GIT_REPOSITORY [email protected]:simdutf/simdutf.git
GIT_SHALLOW TRUE
GIT_TAG tags/v3.2.2
)
FetchContent_MakeAvailable(simdutf)
file(WRITE main.cpp "
#include <iostream>
#include \"simdutf.h\"
int main(int argc, char *argv[]) {
const char * ascii = \"1234\";
bool validutf8 = simdutf::validate_utf8(ascii, 4);
if(validutf8) {
std::cout << \"valid UTF-8\" << std::endl;
} else {
std::cout << \"invalid UTF-8\" << std::endl;
return EXIT_FAILURE;
}
char16_t utf16_output[4];
// convert to UTF-16LE
size_t utf16words = simdutf::convert_utf8_to_utf16le(ascii, 4, utf16_output);
std::cout << \"wrote \" << utf16words << \" UTF-16 words.\" << std::endl;
// It wrote utf16words * sizeof(char16_t) bytes.
//
// convert it back:
char buffer[4];
size_t utf8words = simdutf::convert_utf16le_to_utf8(utf16_output, utf16words, buffer);
std::cout << \"wrote \" << utf8words << \" UTF-8 words.\" << std::endl;
return EXIT_SUCCESS;
}")
add_executable(repro main.cpp)
target_link_libraries(repro PUBLIC simdutf::simdutf)
from simdutf.
I am going to close the issue. The reporter is correct, they need two files for the single-header version.
from simdutf.
As a last remark: we do not and probably never will support having both the single-header and another version of the simdutf library in the same project. It is the same code, same library, just packaged differently. Many users find the single-header version simpler.
from simdutf.
If you use the single-header release, then two files must be installed the header (there is just one) and the source file.
I understand, but I expected "single-header" to be "header-only". And I've never seen the inclusion of a .cpp
file in other projects. You are free to use any distribution method you want, of course, just wanted to know your motivation for this.
I am not sure what you mean by both at the same time
I meant simultaneous installation, not usage. So you can package both versions of the library and give users a chance to select the version they want. Currently, IIUC, you need to create 2 different packages or manually rename/move files.
from simdutf.
If you believe that there is a shortcoming, please consider providing a pull request.
from simdutf.
Related Issues (20)
- Incorrect #define for icelake HOT 2
- Slow performance compared to v8 String::NewFromUtf8 HOT 8
- Add SVE support HOT 3
- Feature request: UTF8 Byte Length HOT 6
- Split out `simdutf::validate_utf8()` HOT 3
- Add support for Big Endian systems HOT 3
- Add support for WebAssembly SIMD128 HOT 2
- For short strings `convert_utf8_to_utf16le_with_errors` may sometimes cause buffer overflows by reading before the buffer when the input is not UTF-8 HOT 8
- Add Windows on ARM support HOT 3
- v3.2.1 build failure on arm64 macOS HOT 2
- Compiling with clang on windows fails HOT 1
- Detect best implementation at compile time HOT 2
- `convert_valid_utf16_to_utf8` produces incorrect result HOT 1
- Excessive check for CLMUL on "Westmere" path HOT 8
- SIGILL on convert_utf8_to_utf16le HOT 26
- Implement latin 1 to UTF-8 "length" functions
- Compiler warning (level 2) C4146 with VS 2022 latest version HOT 3
- Build failure on CPU without popcnt HOT 8
- crash when converting during the initialization of a static object. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simdutf.