Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stringstream not working on Android #16

Closed
fatmingwang opened this issue Oct 21, 2015 · 1 comment
Closed

stringstream not working on Android #16

fatmingwang opened this issue Oct 21, 2015 · 1 comment

Comments

@fatmingwang
Copy link

the code in muParser.cpp
int Parser::IsVal(const char_type* a_szExpr, int *a_iPos, value_type *a_fVal)
{
....
....
below one will crash on android(NDK)
stream >> fVal;//stringstream not working right on android plaform
....
}

so I have change as
//return how many string is legal for value,if return 0 this is not a value
inline int Mywtof( const wchar_t* e_str,double_e_pdValue )
int Parser::IsVal(const char_type_ a_szExpr, int *a_iPos, value_type *a_fVal)
{
value_type fVal(0);
int l_iValueLength = Mywtof(a_szExpr,&fVal);
if( l_iValueLength == 0 )
return 0;
*a_iPos += l_iValueLength;
*a_fVal = fVal;
return 1;
}

inline int Mywtof( const wchar_t* e_str,double*e_pdValue )
{
    int l_iLegalValueLength = 0;
    bool l_bIsValue = true;
    bool bMinus = false;
    if (*e_str == '+')
    {
        e_str++;
    }
    else
    if (*e_str == '-')
    {
        bMinus = true;
        e_str++;
    }
    double  l_dbValue = 0.f;
    int     l_dotStart = -1;
    int l_iLength = wcslen(e_str);
    for( int i=0;i<l_iLength;++i )
    {
        if( e_str[i] == L'.' )
        {
            l_dotStart = i;
        }
        else
        if( e_str[i] >= L'0' && e_str[i] <= L'9' )
        {
            l_dbValue = (l_dbValue*10) +(e_str[i]-L'0');
        }
        else
        if( e_str[i] == L'e'||e_str[i] == L'E' )
        {
            int l_ie = e_str[i+2]-L'0';
            for( int j=1;j<l_ie;++j )
                l_dbValue /= 10;
        }
        else
        {
            break;
        }
        ++l_iLegalValueLength;
    }

    if( l_dotStart != -1 )
    {
        float   l_fDotOffset = 1.f;
        for( int j=1;j<l_iLength-l_dotStart;++j )
            l_fDotOffset*=10;
        l_dbValue/=l_fDotOffset;
    }
    *e_pdValue = bMinus?-l_dbValue:l_dbValue;
    return l_iLegalValueLength;
}
@beltoforion
Copy link
Owner

closing the issue since it is more a bug of android than muparser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants