<commit_before>/**
 * @internal
 * @addtogroup Evas_Utils
 *
 * @{
 */
/**
 * @internal
 * @defgroup Evas_Script Evas Script (language) utility functions
 *
 * This set of functions and types helps evas handle scripts correctly.
 * @todo Document types, structures and macros.
 *
 * @{
 */
#include <Eina.h>

#include "evas_language_utils.h"
#include "evas_bidi_utils.h" /* Used for fallback. */
#include "../evas_font_ot.h" /* Used for harfbuzz info */

#ifdef USE_HARFBUZZ
# include <hb.h>
# ifdef HAVE_HARFBUZZ_GLIB
#  include <hb-glib.h>
# endif
#endif

/* FIXME: rename and move */
void *
evas_common_language_unicode_funcs_get(void)
{
#if defined(USE_HARFBUZZ) && defined(HAVE_HARFBUZZ_GLIB)
   return hb_glib_get_unicode_funcs();
#endif
   return NULL;
}

static Evas_Script_Type
_get_script(Eina_Unicode unicode)
{
#ifdef USE_HARFBUZZ
   static hb_unicode_funcs_t *funcs;
   if (!funcs)
        funcs = evas_common_language_unicode_funcs_get();
   return hb_unicode_get_script(funcs, unicode);
#else
   (void) unicode;
#endif
   return EVAS_SCRIPT_COMMON;
}

int
evas_common_language_script_end_of_run_get(const Eina_Unicode *str,
      const Evas_BiDi_Paragraph_Props *bidi_props, size_t start, int len)
{
   /* FIXME: Use the standard segmentation instead */
   if (evas_common_font_ot_is_enabled())
     {
        Evas_Script_Type first = EVAS_SCRIPT_UNKNOWN;
        int i;
        for (i = 0 ; (i < len) ; i++, str++)
          {
            Evas_Script_Type tmp;
            tmp = _get_script(*str);
            /* Arabic is the first script in the array that's not
             * common/inherited. */
            if ((first == EVAS_SCRIPT_UNKNOWN) && (tmp >= EVAS_SCRIPT_COMMON))
              {
                 first = tmp;
                 continue;
              }
            if ((first != tmp) && (tmp >= EVAS_SCRIPT_COMMON))
              {
                 break;
              }
          }
#ifdef BIDI_SUPPORT
          {
             int bidi_end;
             bidi_end = evas_bidi_end_of_run_get(bidi_props, start, len);
             if (bidi_end > 0)
               {
                  i = (i < bidi_end) ? i : bidi_end;
               }
          }
#else
        (void) bidi_props;
        (void) start;
#endif
        return (i < len) ? i : 0;
     }
   else
     {
#ifdef BIDI_SUPPORT
        return evas_bidi_end_of_run_get(bidi_props, start, len);
#endif
     }
   return 0;
}

Evas_Script_Type
evas_common_language_script_type_get(const Eina_Unicode *str)<commit_msg>Evas font-engine: Fixed a bug in evas_common_language_script_end_of_run_get<commit_after>/**
 * @internal
 * @addtogroup Evas_Utils
 *
 * @{
 */
/**
 * @internal
 * @defgroup Evas_Script Evas Script (language) utility functions
 *
 * This set of functions and types helps evas handle scripts correctly.
 * @todo Document types, structures and macros.
 *
 * @{
 */
#include <Eina.h>

#include "evas_language_utils.h"
#include "evas_bidi_utils.h" /* Used for fallback. */
#include "../evas_font_ot.h" /* Used for harfbuzz info */

#ifdef USE_HARFBUZZ
# include <hb.h>
# ifdef HAVE_HARFBUZZ_GLIB
#  include <hb-glib.h>
# endif
#endif

/* FIXME: rename and move */
void *
evas_common_language_unicode_funcs_get(void)
{
#if defined(USE_HARFBUZZ) && defined(HAVE_HARFBUZZ_GLIB)
   return hb_glib_get_unicode_funcs();
#endif
   return NULL;
}

static Evas_Script_Type
_get_script(Eina_Unicode unicode)
{
#ifdef USE_HARFBUZZ
   static hb_unicode_funcs_t *funcs;
   if (!funcs)
        funcs = evas_common_language_unicode_funcs_get();
   return hb_unicode_get_script(funcs, unicode);
#else
   (void) unicode;
#endif
   return EVAS_SCRIPT_COMMON;
}

int
evas_common_language_script_end_of_run_get(const Eina_Unicode *str,
      const Evas_BiDi_Paragraph_Props *bidi_props, size_t start, int len)
{
   /* FIXME: Use the standard segmentation instead */
   if (evas_common_font_ot_is_enabled())
     {
        Evas_Script_Type first = EVAS_SCRIPT_UNKNOWN;
        int i;
        for (i = start, str += start ; (i < len) ; i++, str++)
          {
            Evas_Script_Type tmp;
            tmp = _get_script(*str);
            /* Arabic is the first script in the array that's not
             * common/inherited. */
            if ((first == EVAS_SCRIPT_UNKNOWN) && (tmp >= EVAS_SCRIPT_COMMON))
              {
                 first = tmp;
                 continue;
              }
            if ((first != tmp) && (tmp >= EVAS_SCRIPT_COMMON))
              {
                 break;
              }
          }
        i = i - start;
#ifdef BIDI_SUPPORT
          {
             int bidi_end;
             bidi_end = evas_bidi_end_of_run_get(bidi_props, start, len);
             if (bidi_end > 0)
               {
                  i = (i < bidi_end) ? i : bidi_end;
               }
          }
#else
        (void) bidi_props;
        (void) start;
#endif
        return (i < len) ? i : 0;
     }
   else
     {
#ifdef BIDI_SUPPORT
        return evas_bidi_end_of_run_get(bidi_props, start, len);
#endif
     }
   return 0;
}

Evas_Script_Type
evas_common_language_script_type_get(const Eina_Unicode *str)
{'fraction_non_alphanumeric': 0.10264446620959844, 'fraction_numerical': 0.0013712047012732615, 'mean_word_length': 2.37029702970297, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3134624', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1804, 'n_words': 392}