view modules/web/src/main/native/Source/WTF/wtf/java/StringJava.cpp @ 5976:94331ac42150

RT-25869: Update copyright year in header of modified source code files to 2013 Reviewed-by: Mong Hang Vo
author kcr
date Mon, 23 Dec 2013 13:46:39 -0800
parents bcd662ba5826
children
line wrap: on
line source
/*
 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
 */
#include "config.h"

#include <wtf/text/WTFString.h>

namespace WTF {

// String conversions
String::String(JNIEnv* env, const JLString &s)
{
    if (!s) {
        m_impl = StringImpl::empty();
    } else {
        unsigned int len = env->GetStringLength(s);
        if (!len) {
            m_impl = StringImpl::empty();
        } else {
            const jchar* str = env->GetStringCritical(s, NULL);
            if (str) {
                m_impl = StringImpl::create((const UChar*)str, len);
                env->ReleaseStringCritical(s, str);
            } else {
                m_impl = StringImpl::create(reinterpret_cast<const UChar*>(L"OME"), 3);
            }
        }
    }
}

JLString String::toJavaString(JNIEnv *env) const
{
    return isNull()
        ? NULL
        : env->NewString((jchar*)(characters()), length());
}

} // namespace WTF