cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsoref <...@git.apache.org>
Subject [GitHub] cordova-plugin-globalization pull request: BB10 implementation
Date Wed, 30 Jul 2014 18:34:10 GMT
Github user jsoref commented on a diff in the pull request:

    https://github.com/apache/cordova-plugin-globalization/pull/18#discussion_r15603064
  
    --- Diff: src/blackberry10/native/public/plugin.cpp ---
    @@ -0,0 +1,320 @@
    +#include "plugin.h"
    +#include "tokenizer.h"
    +
    +#ifdef _WINDOWS
    +#include <windows.h>
    +BOOL APIENTRY DllMain( HANDLE hModule,
    +                       DWORD ul_reason_for_call,
    +                       LPVOID lpReserved )
    +{
    +    return TRUE;
    +}
    +#else
    +#include <errno.h>
    +#include <string.h>
    +
    +extern int errno;
    +#endif
    +
    +SendPluginEv SendPluginEvent;
    +
    +string g_GetSysErrMsg( void )
    +{
    +    string strError = "Unknown";
    +    // Problem loading
    +#ifdef _WINDOWS
    +    int nErrorCode = GetLastError();
    +    LPTSTR s;
    +    if ( ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
    +    NULL, nErrorCode, 0, ( LPTSTR ) &s, 0, NULL ) )
    +    {
    +        strError = s;
    +    }
    +    else
    +    {
    +        char szBuf[ 20 ];
    +        _snprintf_s( szBuf, _countof(szBuf), 19, "%d", nErrorCode );
    +        strError = szBuf;
    +    }
    +#else
    +    char szError[80];
    +    if ( strerror_r( errno, szError, sizeof(szError)  ) )
    +    {
    +        strError = "no description found";
    +    }
    +    else
    +    {
    +        strError = szError;
    +    }
    +#endif
    +    return strError;
    +}
    +
    +void g_sleep( unsigned int mseconds )
    +{
    +#ifdef _WINDOWS
    +    Sleep( mseconds );
    +#else
    +    usleep( mseconds * 1000 );
    +#endif
    +}
    +
    +string& g_trim( string& str )
    +{
    +    // Whitespace characters
    +    char whspc[] = " \t\r\n\v\f";
    +
    +    // Whack off first part
    +    size_t pos = str.find_first_not_of( whspc );
    +
    +    if ( pos != string::npos )
    +        str.replace( 0, pos, "" );
    +
    +    // Whack off trailing stuff
    +    pos = str.find_last_not_of( whspc );
    +
    +    if ( pos != string::npos )
    +        str.replace( pos + 1, str.length() - pos, "" );
    +
    +    return str;
    +}
    +
    +void g_tokenize( const string& str, const string& delimiters, vector<string>&
tokens )
    +{
    +    tokenize( str, tokens, delimiters );
    +}
    +
    +char* SetEventFunc( SendPluginEv funcPtr )
    +{
    +    static char * szObjList = onGetObjList();
    +    SendPluginEvent = funcPtr;
    +    return szObjList;
    +}
    +
    +
    +const int nMAXSIZE = 512;
    +char* g_pszRetVal = NULL;
    +
    +//-----------------------------------------------------------
    +// Map from an object Id to an object instance
    +//-----------------------------------------------------------
    +typedef std::map<string, JSExt*> StringToJExt_T;
    +
    +//-----------------------------------------------------------
    +// Map from a browser context to an id mapping
    +//-----------------------------------------------------------
    +typedef std::map<void*, StringToJExt_T*> VoidToMap_T;
    +
    +VoidToMap_T g_context2Map;
    +
    +class GlobalSharedModule
    +{
    +
    +public:
    +    GlobalSharedModule( void )
    +    {
    +        g_pszRetVal = new char[ nMAXSIZE ];
    +    }
    +
    +    ~GlobalSharedModule()
    +    {
    +        delete [] g_pszRetVal;
    +
    +        VoidToMap_T::iterator posMaps;
    +
    +        for ( posMaps = g_context2Map.begin(); posMaps != g_context2Map.end(); ++posMaps
)
    +        {
    +            StringToJExt_T& id2Obj = *posMaps->second;
    +            StringToJExt_T::iterator posMap;
    +
    +            for ( posMap = id2Obj.begin(); posMap != id2Obj.end(); ++posMap )
    +            {
    +                JSExt* pJSExt = posMap->second;
    +
    +                if ( pJSExt->CanDelete() )
    +                {
    +                    delete pJSExt;
    +                }
    +            }
    +
    +            id2Obj.erase( id2Obj.begin(), id2Obj.end() );
    +        }
    +
    +        g_context2Map.erase( g_context2Map.begin(), g_context2Map.end() );
    +    }
    +};
    +
    +GlobalSharedModule g_sharedModule;
    +
    +char* g_str2global( const string& strRetVal )
    +{
    +    int nLen = strRetVal.size();
    +
    +    if ( nLen >= nMAXSIZE )
    +    {
    +        delete [] g_pszRetVal;
    +        g_pszRetVal = new char[ nLen + 1 ];
    +    }
    +
    +    else
    +    {
    +        // To minimaize the number of memory reallocations, the assumption
    --- End diff --
    
    sp: minimaize


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message