string reverseVowels(string s) {
     if(s.size() == 0 )return s;
     int i=0,j=s.size()-1;
     while(i<j){
         while(!isV(s[i]) && i<=j)i++;
         while(!isV(s[j]) && j>=0)j--;
         if(i>=j)break;
         char t = s[i];
         s[i]=s[j];
         s[j]=t;
         i++;
         j--;
     }
     return s;
     
 }
Exemplo n.º 2
0
int getTeg(char *str){
    int sum = 0;
    sum = isMODEL (str)+
    isP        (str)+
    isSCORE    (str)+
    isCOMP     (str)+
    isRFILTER  (str)+
    isPFILTERs (str)+
    isPFILTER  (str)+
    isSIZEX    (str)+
    isSIZEY    (str)+
    isWEIGHTS  (str)+
    isV        (str)+
    isVx       (str)+
    isVy       (str)+
    isD        (str)+
    isDx       (str)+
    isDy       (str)+
    isDxx      (str)+
    isDyy      (str)+
    isB        (str)+
    isPCA         (str)+
    isCASCADE_Th  (str)+
    isHYPOTHES_PCA(str)+
    isDEFORM_PCA  (str)+
    isHYPOTHES    (str)+
    isDEFORM      (str)+
    isWEIGHTS_PCA (str)+
    isPCAcoeff    (str)
    ;

    return sum;
}
Exemplo n.º 3
0
int getTeg(char *str){
    int sum = 0;
    sum = isMODEL (str)+
    isP        (str)+
    isSCORE    (str)+
    isCOMP     (str)+
    isRFILTER  (str)+
    isPFILTERs (str)+
    isPFILTER  (str)+
    isSIZEX    (str)+
    isSIZEY    (str)+
    isWEIGHTS  (str)+
    isV        (str)+
    isVx       (str)+
    isVy       (str)+
    isD        (str)+
    isDx       (str)+
    isDy       (str)+
    isDxx      (str)+
    isDyy      (str)+
    isB        (str);

    return sum;
}
Exemplo n.º 4
0
/* u and v are the number of vertices in sets U, and V, respectively,
 * filling up bipgraph[0..u-1][0..v-1].
 * result:
 *  matching[u0]==v0 iff u0 and v0 are in the matching, 
 * otherwise matching[u0] = -1 */
void
match(int u, int v) {
  int i,j, head,tail, bad, last, increased;

  for( i = 0; i < u; i++ ) {
    matching[i] = -1;
    flagUmatched[i] = 0;
  }
  for( i = 0; i < v; i++ ) flagVmatched[i] = 0;

  do { /* find alternating paths by repeated bfs. */
    for( i = 0; i < MAXU+MAXV; i++ ) predecessor[i] = -1;
    for( i = 0; i < MAXU; i++ ) flagUused[i] = flagUvisited[i] = 0;
    for( i = 0; i < MAXV; i++ ) flagVused[i] = flagVvisited[i] = 0;
  
    head = tail = 0;

    /* put all the unmatched u's on the queue. They start the 
     * alternating path. */
    for( i = 0; i < u; i++ ) {
      if( ! isMatched(U(i))) {
	queue[tail++] = U(i);
	predecessor[i] = -1; /* redundant statement */
	setVisited(U(i));
      }
    }

    /* flag that at least one path was found by the bfs.
     * when the bfs does not find an alternating path we are done. */
    increased = 0;

    while( head != tail ) {
      i = queue[head++];

      /* this node appeared on some previously found alternating path. */
      if( isUsed(i) ) continue;
    
      if( isV(i) && !isMatched(i) ) {
	/* we got to the end of an alternating path. see if
	 * it is disjoint with other paths found so far. only
	 * then can we mess it up a bit. */
	bad = 0;
	for( j = i; j != -1; j = predecessor[j]) {
	  if( isUsed(j)) {
	    bad = 1;
	    break;
	  }
	}
	
	if( ! bad ) {
	  /* this path is pristine. switch "polarity" of edges
	   * in the matching on this path. */

	  /* flag and instrumention - whether (not) to quit,
	   * and how many paths we found this bfs. */
	  increased++; 
	  for( j = i; j != -1; last = j, j = predecessor[j] ) {
	    if( isV(j) && !isMatched(j)) {
	      /* the only unmatched v - actually this means we
	       * are on the first iteration of this loop. */
	      setMatched(j);

	    } else if( isU(j) ) {
	      if( isMatched(j) ) {
		/* the node we saw in the previous iteration of
		 * this loop must be a V. We will match with it
		 * instead of the one we used to match with, which
		 * must be the next node visited in this loop. */
		assert(isV(last));
		matching[j] = last - MAXU;
	      } else {
		/* we are the very first u, one of the ones the
		 * bfs queue was "seeded" with. We should have ...*/
		assert(predecessor[j] == -1);
		setMatched(j);
		assert(isV(last));
		matching[j] = last - MAXU;
	      }
	    }
	    setUsed(j); /* this node cannot be used for other
			 * paths we might run across in the future
			 * on this bfs. */
	  } /* for */
	} /* if ! bad */
      } /* isV and !isMatched */

      else if( isV(i) ) {
	/* this must be a matched V - find the matching U and put it on 
	 * the queue if it is not visited or used. */

	bad = 1;

	for( j = 0; j < u; j++ ) {
	  if( isMatched(U(j)) && matching[j] == i - MAXU ) {
	    /* this is the one. */
	    if( ! isVisited(U(j)) && !isUsed(U(j))) {
	      setVisited(U(j));
	      queue[tail++] = U(j); 
	      predecessor[U(j)] = i;
	    }
	    bad = 0;
	    break;
	  }
	}
	assert(!bad);
      } /* isV */
      else if( isU(i) ) {
	/* we are at U. whether it is unmatched (a "seed"),
	 * or matched, we do the same thing - put on the queue
	 * all V's which it is connected to in the graph but
	 * which it is _not_ paired to in the current matching. */

	for( j = 0; j < v; j++ ) {
	  if( bipgraph[i][j] &&
	      !isVisited(V(j)) && 
	      !isUsed(V(j)) && 
	      matching[i] != j ) {
	    /* we can put this one on the queue. */
	    queue[tail++] = V(j);
	    predecessor[V(j)] = i;
	    setVisited(V(j));
	  }
	}
      } else {
	assert(0); /* should be no other cases. */
      }
      /* this is the end of the bfs. */
    } 
  } while( increased );

  return;
}
static void
preprocess_text_hangul (const hb_ot_shape_plan_t *plan,
                        hb_buffer_t              *buffer,
                        hb_font_t                *font)
{
  HB_BUFFER_ALLOCATE_VAR (buffer, hangul_shaping_feature);

  /* Hangul syllables come in two shapes: LV, and LVT.  Of those:
   *
   *   - LV can be precomposed, or decomposed.  Lets call those
   *     <LV> and <L,V>,
   *   - LVT can be fully precomposed, partically precomposed, or
   *     fully decomposed.  Ie. <LVT>, <LV,T>, or <L,V,T>.
   *
   * The composition / decomposition is mechanical.  However, not
   * all <L,V> sequences compose, and not all <LV,T> sequences
   * compose.
   *
   * Here are the specifics:
   *
   *   - <L>: U+1100..115F, U+A960..A97F
   *   - <V>: U+1160..11A7, U+D7B0..D7C7
   *   - <T>: U+11A8..11FF, U+D7CB..D7FB
   *
   *   - Only the <L,V> sequences for the 11xx ranges combine.
   *   - Only <LV,T> sequences for T in U+11A8..11C3 combine.
   *
   * Here is what we want to accomplish in this shaper:
   *
   *   - If the whole syllable can be precomposed, do that,
   *   - Otherwise, fully decompose and apply ljmo/vjmo/tjmo features.
   *   - If a valid syllable is followed by a Hangul tone mark, reorder the tone
   *     mark to precede the whole syllable - unless it is a zero-width glyph, in
   *     which case we leave it untouched, assuming it's designed to overstrike.
   *
   * That is, of the different possible syllables:
   *
   *   <L>
   *   <L,V>
   *   <L,V,T>
   *   <LV>
   *   <LVT>
   *   <LV, T>
   *
   * - <L> needs no work.
   *
   * - <LV> and <LVT> can stay the way they are if the font supports them, otherwise we
   *   should fully decompose them if font supports.
   *
   * - <L,V> and <L,V,T> we should compose if the whole thing can be composed.
   *
   * - <LV,T> we should compose if the whole thing can be composed, otherwise we should
   *   decompose.
   */

  buffer->clear_output ();
  unsigned int start = 0, end = 0; /* Extent of most recently seen syllable;
                                    * valid only if start < end
                                    */
  unsigned int count = buffer->len;

  for (buffer->idx = 0; buffer->idx < count && !buffer->in_error;)
  {
    hb_codepoint_t u = buffer->cur().codepoint;

    if (isHangulTone (u))
    {
      /*
       * We could cache the width of the tone marks and the existence of dotted-circle,
       * but the use of the Hangul tone mark characters seems to be rare enough that
       * I didn't bother for now.
       */
      if (start < end && end == buffer->out_len)
      {
        /* Tone mark follows a valid syllable; move it in front, unless it's zero width. */
        buffer->next_glyph ();
        if (!is_zero_width_char (font, u))
        {
          buffer->merge_out_clusters (start, end + 1);
          hb_glyph_info_t *info = buffer->out_info;
          hb_glyph_info_t tone = info[end];
          memmove (&info[start + 1], &info[start], (end - start) * sizeof (hb_glyph_info_t));
          info[start] = tone;
        }
      }
      else
      {
        /* No valid syllable as base for tone mark; try to insert dotted circle. */
        if (font->has_glyph (0x25CCu))
        {
          hb_codepoint_t chars[2];
          if (!is_zero_width_char (font, u)) {
            chars[0] = u;
            chars[1] = 0x25CCu;
          } else {
            chars[0] = 0x25CCu;
            chars[1] = u;
          }
          buffer->replace_glyphs (1, 2, chars);
        }
        else
        {
          /* No dotted circle available in the font; just leave tone mark untouched. */
          buffer->next_glyph ();
        }
      }
      start = end = buffer->out_len;
      continue;
    }

    start = buffer->out_len; /* Remember current position as a potential syllable start;
                              * will only be used if we set end to a later position.
                              */

    if (isL (u) && buffer->idx + 1 < count)
    {
      hb_codepoint_t l = u;
      hb_codepoint_t v = buffer->cur(+1).codepoint;
      if (isV (v))
      {
        /* Have <L,V> or <L,V,T>. */
        hb_codepoint_t t = 0;
        unsigned int tindex = 0;
        if (buffer->idx + 2 < count)
        {
          t = buffer->cur(+2).codepoint;
          if (isT (t))
            tindex = t - TBase; /* Only used if isCombiningT (t); otherwise invalid. */
          else
            t = 0; /* The next character was not a trailing jamo. */
        }

        /* We've got a syllable <L,V,T?>; see if it can potentially be composed. */
        if (isCombiningL (l) && isCombiningV (v) && (t == 0 || isCombiningT (t)))
        {
          /* Try to compose; if this succeeds, end is set to start+1. */
          hb_codepoint_t s = SBase + (l - LBase) * NCount + (v - VBase) * TCount + tindex;
          if (font->has_glyph (s))
          {
            buffer->replace_glyphs (t ? 3 : 2, 1, &s);
            if (unlikely (buffer->in_error))
              return;
            end = start + 1;
            continue;
          }
        }

        /* We didn't compose, either because it's an Old Hangul syllable without a
         * precomposed character in Unicode, or because the font didn't support the
         * necessary precomposed glyph.
         * Set jamo features on the individual glyphs, and advance past them.
         */
        buffer->cur().hangul_shaping_feature() = LJMO;
        buffer->next_glyph ();
        buffer->cur().hangul_shaping_feature() = VJMO;
        buffer->next_glyph ();
        if (t)
        {
          buffer->cur().hangul_shaping_feature() = TJMO;
          buffer->next_glyph ();
          end = start + 3;
        }
        else
          end = start + 2;
        if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES)
          buffer->merge_out_clusters (start, end);
        continue;
      }
    }

    else if (isCombinedS (u))
    {
      /* Have <LV>, <LVT>, or <LV,T> */
      hb_codepoint_t s = u;
      bool has_glyph = font->has_glyph (s);
      unsigned int lindex = (s - SBase) / NCount;
      unsigned int nindex = (s - SBase) % NCount;
      unsigned int vindex = nindex / TCount;
      unsigned int tindex = nindex % TCount;

      if (!tindex &&
          buffer->idx + 1 < count &&
          isCombiningT (buffer->cur(+1).codepoint))
      {
        /* <LV,T>, try to combine. */
        unsigned int new_tindex = buffer->cur(+1).codepoint - TBase;
        hb_codepoint_t new_s = s + new_tindex;
        if (font->has_glyph (new_s))
        {
          buffer->replace_glyphs (2, 1, &new_s);
          if (unlikely (buffer->in_error))
            return;
          end = start + 1;
          continue;
        }
      }

      /* Otherwise, decompose if font doesn't support <LV> or <LVT>,
       * or if having non-combining <LV,T>.  Note that we already handled
       * combining <LV,T> above. */
      if (!has_glyph ||
          (!tindex &&
           buffer->idx + 1 < count &&
           isT (buffer->cur(+1).codepoint)))
      {
        hb_codepoint_t decomposed[3] = {LBase + lindex,
                                        VBase + vindex,
                                        TBase + tindex};
        if (font->has_glyph (decomposed[0]) &&
            font->has_glyph (decomposed[1]) &&
            (!tindex || font->has_glyph (decomposed[2])))
        {
          unsigned int s_len = tindex ? 3 : 2;
          buffer->replace_glyphs (1, s_len, decomposed);
          if (unlikely (buffer->in_error))
            return;

          /* We decomposed S: apply jamo features to the individual glyphs
           * that are now in buffer->out_info.
           */
          hb_glyph_info_t *info = buffer->out_info;

          /* If we decomposed an LV because of a non-combining T following,
           * we want to include this T in the syllable.
           */
          if (has_glyph && !tindex)
          {
            buffer->next_glyph ();
            s_len++;
          }
          end = start + s_len;

          unsigned int i = start;
          info[i++].hangul_shaping_feature() = LJMO;
          info[i++].hangul_shaping_feature() = VJMO;
          if (i < end)
            info[i++].hangul_shaping_feature() = TJMO;
          if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES)
            buffer->merge_out_clusters (start, end);
          continue;
        }
      }

      if (has_glyph)
      {
        /* We didn't decompose the S, so just advance past it. */
        end = start + 1;
        buffer->next_glyph ();
        continue;
      }
    }

    /* Didn't find a recognizable syllable, so we leave end <= start;
     * this will prevent tone-mark reordering happening.
     */
    buffer->next_glyph ();
  }
  buffer->swap_buffers ();
}