(root)/
fribidi-1.0.13/
lib/
fribidi-brackets.c
       1  /* fribidi-brackets.c - get bracketed character
       2   *
       3   * Copyright (C) 2004  Sharif FarsiWeb, Inc
       4   * Copyright (C) 2001, 2002, 2004  Behdad Esfahbod
       5   * Copyright (C) 1999, 2000, 2017  Dov Grobgeld
       6   *
       7   * This file is part of GNU FriBidi.
       8   * 
       9   * GNU FriBidi is free software; you can redistribute it and/or
      10   * modify it under the terms of the GNU Lesser General Public License
      11   * as published by the Free Software Foundation; either version 2.1
      12   * of the License, or (at your option) any later version.
      13   * 
      14   * GNU FriBidi is distributed in the hope that it will be useful,
      15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17   * GNU Lesser General Public License for more details.
      18   * 
      19   * You should have received a copy of the GNU Lesser General Public License
      20   * along with GNU FriBidi; if not, write to the Free Software
      21   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
      22   * 
      23   * For licensing issues, contact <fribidi.license@gmail.com> or write to
      24   * Sharif FarsiWeb, Inc., PO Box 13445-389, Tehran, Iran.
      25   */
      26  /* 
      27   * Author(s):
      28   *   Behdad Esfahbod, 2001, 2002, 2004
      29   *   Dov Grobgeld, 1999, 2000, 2017
      30   */
      31  
      32  #include "common.h"
      33  
      34  #include <fribidi-brackets.h>
      35  
      36  #include "brackets.tab.i"
      37  #include "brackets-type.tab.i"
      38  #include <stdio.h>
      39  
      40  #define FRIBIDI_TYPE_BRACKET_OPEN 2
      41  
      42  FRIBIDI_ENTRY FriBidiBracketType
      43  fribidi_get_bracket (
      44    /* input */
      45    FriBidiChar ch
      46  )
      47  {
      48    FriBidiBracketType bracket_type;
      49    register uint8_t char_type = FRIBIDI_GET_BRACKET_TYPE (ch);
      50  
      51    /* The bracket type from the table may be:
      52          0 - Not a bracket
      53  	1 - a bracket
      54  	2 - closing.
      55  
      56       This will be recodeded into the FriBidiBracketType as having a
      57       bracket_id = 0 if the character is not a bracket.
      58     */
      59    fribidi_boolean is_open = false;
      60  
      61    if (char_type == 0)
      62      bracket_type = FRIBIDI_NO_BRACKET;
      63    else
      64    {
      65      is_open = (char_type & FRIBIDI_TYPE_BRACKET_OPEN) != 0;
      66      bracket_type = FRIBIDI_GET_BRACKETS (ch) & FRIBIDI_BRACKET_ID_MASK;
      67    }
      68    if (is_open)
      69      bracket_type |= FRIBIDI_BRACKET_OPEN_MASK;
      70  
      71    return bracket_type;
      72  }
      73  
      74  FRIBIDI_ENTRY void
      75  fribidi_get_bracket_types (
      76    /* input */
      77    const FriBidiChar *str,
      78    const FriBidiStrIndex len,
      79    const FriBidiCharType *types,
      80    /* output */
      81    FriBidiBracketType *btypes
      82  )
      83  {
      84    FriBidiStrIndex i;
      85    for (i=0; i<len; i++)
      86      {
      87        /* Optimization that bracket must be of types ON */
      88        if (*types == FRIBIDI_TYPE_ON)
      89  	*btypes = fribidi_get_bracket (*str);
      90        else
      91  	*btypes = FRIBIDI_NO_BRACKET;
      92  
      93        btypes++;
      94        types++;
      95        str++;
      96      }
      97  }
      98  
      99  /* Editor directions:
     100   * Local Variables:
     101   *   mode: c
     102   *   c-basic-offset: 2
     103   *   indent-tabs-mode: t
     104   *   tab-width: 8
     105   * End:
     106   * vim: textwidth=78: autoindent: cindent: shiftwidth=2: tabstop=8:
     107   */