<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#undef OSL_DEBUG_LEVEL


#include <osl/diagnose.h>

#include "internal/config.hxx"
#include "internal/utilities.hxx"

//-----------------------------
// constants
//-----------------------------

const size_t MAX_RES_STRING = 1024;
const wchar_t SPACE_CHAR = _T(' ');

//---------------------------------
/**
*/
std::wstring StringToWString(const std::string& String)
{
    int len = MultiByteToWideChar(
        CP_ACP, 0, String.c_str(), -1, 0, 0);

    wchar_t* buff = reinterpret_cast<wchar_t*>(
        _alloca(len * sizeof(wchar_t)));

    MultiByteToWideChar(
        CP_ACP, 0, String.c_str(), -1, buff, len);

    return std::wstring(buff);
}

//---------------------------------
/**
*/
std::string WStringToString(const std::wstring& String)
{
    int len = WideCharToMultiByte(
        CP_ACP, 0, String.c_str(), -1, 0, 0, 0, 0);

    char* buff = reinterpret_cast<char*>(
        _alloca(len * sizeof(char)));

    WideCharToMultiByte(
        CP_ACP, 0, String.c_str(), -1, buff, len, 0, 0);

    return std::string(buff);
}

//---------------------------------
/**
*/
std::wstring GetResString(int ResId)
{
    wchar_t szResStr[MAX_RES_STRING];

    int rc = LoadStringW( GetModuleHandleW(MODULE_NAME), ResId, szResStr, sizeof(szResStr) );

    OutputDebugStringFormat( "GetResString: read %d chars\n", rc );
    OSL_ENSURE(rc, "String resource not found");

    return std::wstring(szResStr);
}

//---------------------------------
/**
*/
bool is_windows_xp_or_above()
{
    OSVERSIONINFO osvi;
    ZeroMemory(&osvi, sizeof(osvi));
    osvi.dwOSVersionInfoSize = sizeof(osvi);
    GetVersionEx(&osvi);

    // LLA: check for windows xp or above (Vista)
    if (osvi.dwMajorVersion > 5 ||
        (5 == osvi.dwMajorVersion && osvi.dwMinorVersion >= 1))
    {
        return true;
    }
    return false;
}

//---------------------------------
/**
*/

void SaveDebugInfoToFile( const std::wstring& str )
{
   int handle;

   if ((handle = open("c:\\temp\\SHELLRESULT.$$$", O_CREAT | O_RDWR | O_APPEND )) == -1)
   {
      perror("Error: open file error");
      return;
   }
   write(handle, str.c_str(), str.length() );
   close(handle);
}

//---------------------------------
/** helper function to judge if the string is only has spaces.
    @returns<commit_msg>shell: remove dead SaveDebugInfoToFile<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#undef OSL_DEBUG_LEVEL


#include <osl/diagnose.h>

#include "internal/config.hxx"
#include "internal/utilities.hxx"

//-----------------------------
// constants
//-----------------------------

const size_t MAX_RES_STRING = 1024;
const wchar_t SPACE_CHAR = _T(' ');

//---------------------------------
/**
*/
std::wstring StringToWString(const std::string& String)
{
    int len = MultiByteToWideChar(
        CP_ACP, 0, String.c_str(), -1, 0, 0);

    wchar_t* buff = reinterpret_cast<wchar_t*>(
        _alloca(len * sizeof(wchar_t)));

    MultiByteToWideChar(
        CP_ACP, 0, String.c_str(), -1, buff, len);

    return std::wstring(buff);
}

//---------------------------------
/**
*/
std::string WStringToString(const std::wstring& String)
{
    int len = WideCharToMultiByte(
        CP_ACP, 0, String.c_str(), -1, 0, 0, 0, 0);

    char* buff = reinterpret_cast<char*>(
        _alloca(len * sizeof(char)));

    WideCharToMultiByte(
        CP_ACP, 0, String.c_str(), -1, buff, len, 0, 0);

    return std::string(buff);
}

//---------------------------------
/**
*/
std::wstring GetResString(int ResId)
{
    wchar_t szResStr[MAX_RES_STRING];

    int rc = LoadStringW( GetModuleHandleW(MODULE_NAME), ResId, szResStr, sizeof(szResStr) );

    OutputDebugStringFormat( "GetResString: read %d chars\n", rc );
    OSL_ENSURE(rc, "String resource not found");

    return std::wstring(szResStr);
}

//---------------------------------
/**
*/
bool is_windows_xp_or_above()
{
    OSVERSIONINFO osvi;
    ZeroMemory(&osvi, sizeof(osvi));
    osvi.dwOSVersionInfoSize = sizeof(osvi);
    GetVersionEx(&osvi);

    // LLA: check for windows xp or above (Vista)
    if (osvi.dwMajorVersion > 5 ||
        (5 == osvi.dwMajorVersion && osvi.dwMinorVersion >= 1))
    {
        return true;
    }
    return false;
}

//---------------------------------
/** helper function to judge if the string is only has spaces.
    @returns
{'fraction_non_alphanumeric': 0.2265497249888509, 'fraction_numerical': 0.011149100639215103, 'mean_word_length': 2.595938001068947, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2135344', 'n_tokens_mistral': 2123, 'n_tokens_neox': 1989, 'n_words': 607}