Comments (8)
when I switch the prelude to https://github.com/andyarvanitis/purescript-prelude
the example 1 error gone, because eqString using eqStringImpl
auto eqString() -> boxed {
return Data_Eq::Eq()(Data_Eq::eqStringImpl());
};
but the _indexOf is still not found in ffi, I wonder How to get the indexof right?
from purescript-native.
https://github.com/LATBauerdick/purescript-native-ffi/blob/be94de6cedbe273d98d7ac3f1addae5158a8e38a/latb/strings.cpp#L101
I found this file implement it !
from purescript-native.
next unimplement ffi is _unsafeCodePointAt0, I'will work this out tomorrow!
from purescript-native.
Great, thanks for trying this out. Please see this issue for more information on the prelude refEq issues, and let me know if you need help with the other ffi parts you need to implement for your project.
from purescript-native.
I write some naive ffi implemetion.
It's very buggy, takes me whole day ....
I need you help! Help me correct the naive code!
FOREIGN_BEGIN( Data_String_Common )
// split::Pattern->String->Array String
exports["split"] = [](const boxed& p_) -> boxed {
return [=](const boxed& src_) -> boxed {
const string& p = unbox<string>(p_);
const string& s = unbox<string>(src_);
size_t pos_start = 0, pos_end, delim_len = p.length();
string token;
array_t res;
if (p.length() == 0 || s.length() == 0)
{
res.push_back(boxed(s));
return res;
}
if (p.length() > 0 && s.length() > 0)
{
while ((pos_end = s.find(p, pos_start)) != string::npos) {
token = s.substr(pos_start, pos_end - pos_start);
pos_start = pos_end + delim_len;
res.push_back(boxed(token));
}
res.push_back(boxed(s.substr(pos_start)));
}
return res;
};
};
FOREIGN_END
FOREIGN_BEGIN(Data_String_CodePoints)
//foreign import _unsafeCodePointAt0
//:: (String->CodePoint)
//->String
//->CodePoint
exports["_unsafeCodePointAt0"] = [](const boxed& fallBack) -> boxed {
return [=](const boxed & str) -> boxed {
const string& s = unbox<string>(str);
if (s.length() < 1)
{
return fallBack(str);
//return fallBack(); this code also compile, which one I should use??
}
else
{
return s[0]; // the code is wrong , bcz chinese character takes 2 or more byte.
}
};
};
exports["_toCodePointArray"] = [](const boxed& fallBack) -> boxed{
return [=](const boxed & unsafeCodePointAt0) -> boxed {
return [=](const boxed & str) -> boxed {
const string& s = unbox<string>(str);
if (s.length() < 1)
{
//printf("fall back\n");
return fallBack(str);
}
else
{
array_t result;
for (char c : s) {
result.push_back(boxed(c));
}
return result;
}
};
};
};
// -- Returns the first `n` characters of the string.
// foreign import take :: Int -> String -> String
exports["_take"] = [](const boxed& fallBack) -> boxed {
return [=](const boxed& n_) -> boxed {
return [=](const boxed& s_) -> boxed {
const string& s = unbox<string>(s_);
auto n = std::max(unbox<int>(n_), 0);
auto l = s.size();
return n >= l ? s : (n < 1 ? string("") : s.substr(0, n)); // the code is wrong , bcz chinese character takes 2 or more byte.
};
};
};
FOREIGN_END
from purescript-native.
charAt ffi:
FOREIGN_BEGIN(Data_String_Unsafe)
//-- | Returns the character at the given index.
//-- |
//-- | **Unsafe:** throws runtime exception if the index is out of bounds.
//foreign import charAt::Int->String->Char
exports["charAt"] = [](const boxed& index_) -> boxed {
return [=](const boxed& str_) -> boxed {
const string& str = unbox<string>(str_);
const int & index = unbox<int>(index_);
assert(str.length() >index && index >= 0);
return str.substr(index, 1);;
};
};
FOREIGN_END
from purescript-native.
Ok, I can help with those -- unicode (UTF-8) support has been on my to-do list for a while. I can try to work on it this week (or probably this weekend), and I don't think it should take long, since I already have a general idea of how I will do it.
from purescript-native.
It'll be fantastic if this project support unicode! looking forward it!
from purescript-native.
Related Issues (20)
- ObjectUpdate seems to need deep copy HOT 2
- Cannot find ls/ls.h and rs/rs.h HOT 2
- Incorrect equality check in Data_Interval_Duration_Iso HOT 3
- Returning a constant from the ffi HOT 7
- "attribute 'haskell-nix' missing" when building with nix HOT 3
- error building purescript-dotlang HOT 16
- Support spago alternate entry point option
- ffi array type interop with opaque types HOT 7
- zero-fill shift right operator doesn't exist HOT 11
- pass arguments to run HOT 2
- stack nix integration HOT 1
- Problems with nix toolchain HOT 9
- Consider combining executables (and specify backend with switch) HOT 5
- un-gitignore cabal files HOT 2
- cpp binary size HOT 4
- Update to PureScript 0.14 HOT 5
- Webassembly / Emscripten with C++ HOT 1
- Upgrade to Latest PureScript Version
- Backend "psgo" exited with error:1 HOT 2
- go module initialization HOT 9
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 purescript-native.