コード例 #1
0
ファイル: util_dp_fasta_nw.c プロジェクト: cbcrg/tcoffee
int ktup_pair_wise (Alignment *A,int*ns, int **l_s,Constraint_list *CL)
    {
      static char **gl;
      static int ng;
      char *seq1;
      char *seq2;

      int min_len=10;



      if ( !gl)
	gl=make_group_aa (&ng, "vasiliky");


      if ( ns[0]>1)seq1=sub_aln2cons_seq_mat (A, ns[0], l_s[0],"blosum62mt");
      else
	{
	  seq1=(char*)vcalloc ( strlen (A->seq_al[l_s[0][0]])+1, sizeof (char));
	  sprintf ( seq1, "%s",A->seq_al[l_s[0][0]]);
	}
      if ( ns[1]>1)seq2=sub_aln2cons_seq_mat (A, ns[1], l_s[1],"blosum62mt");
      else
	{
	  seq2=(char*)vcalloc ( strlen (A->seq_al[l_s[1][0]])+1, sizeof (char));
	  sprintf ( seq2, "%s",A->seq_al[l_s[1][0]]);
	}

      if ( strlen (seq1)<min_len || strlen (seq2)<min_len)
	{
	  Alignment *B;

	  ungap(seq1); ungap(seq2);
	  B=align_two_sequences ( seq1, seq2, "blosum62mt",-10, -1, "myers_miller_pair_wise");
	  A->score=A->score_aln=aln2sim(B, "idmat");
	  free_aln (B);
	  return A->score;
	}
      else
	{

	  string_convert (seq1, ng, gl);
	  string_convert (seq2, ng, gl);
	  A->score=A->score_aln=ktup_comparison (seq1,seq2, CL->ktup);
	}

      vfree (seq1); vfree (seq2);
      return A->score;
    }
コード例 #2
0
ファイル: iconvpp.hpp プロジェクト: joncampbell123/dosbox-x
    dst_string string_convert(const src_string &src) {
        dst_string res;

        string_convert(res,src);

        return res;
    }
コード例 #3
0
ファイル: iconvpp.hpp プロジェクト: joncampbell123/dosbox-x
    int string_convert_src(const src_string &src) {
        set_src(src);

        int err = string_convert();

        finish();
        return err;
    }
コード例 #4
0
ファイル: iconvpp.hpp プロジェクト: joncampbell123/dosbox-x
    int string_convert_dest(dst_string &dst) {
        size_t srcl = (size_t)((uintptr_t)src_ptr_fence - (uintptr_t)src_ptr);

        dst.resize(std::max(dst.size(),((srcl+4u)*4u)+2u));
        set_dest(dst);

        int err = string_convert();

        finish();
        return err;
    }
コード例 #5
0
ファイル: ui.c プロジェクト: CikaZvone/neovim
void ui_write(char_u *s, int len)
{
#ifndef NO_CONSOLE
  /* Don't output anything in silent mode ("ex -s") unless 'verbose' set */
  if (!(silent_mode && p_verbose == 0)) {
    char_u  *tofree = NULL;

    if (output_conv.vc_type != CONV_NONE) {
      /* Convert characters from 'encoding' to 'termencoding'. */
      tofree = string_convert(&output_conv, s, &len);
      if (tofree != NULL)
        s = tofree;
    }

    mch_write(s, len);

    if (output_conv.vc_type != CONV_NONE)
      vim_free(tofree);
  }
#endif
}
コード例 #6
0
ファイル: remote.c プロジェクト: moriyoshi/mod_vim
/*
 * If conversion is needed, convert "data" from "client_enc" to 'encoding' and
 * return an allocated string.  Otherwise return "data".
 * "*tofree" is set to the result when it needs to be freed later.
 */
static char *serverConvert(VimRemotingClient *client, const char *client_enc, char *data, char **tofree)
{
    char *res = data;

    *tofree = 0;
    if (client_enc && client->enc) {
        vimconv_T vimconv;

        vimconv.vc_type = CONV_NONE;
        if (!convert_setup(&vimconv, client_enc, client->enc) &&
                vimconv.vc_type != CONV_NONE)
        {
            res = string_convert(&vimconv, data, NULL);
            if (res == NULL)
                res = data;
            else
                *tofree = res;
        }
        convert_setup(&vimconv, NULL, NULL);
    }
    return res;
}
コード例 #7
0
ファイル: json.c プロジェクト: KamarajuKusumanchi/vim
    static void
write_string(garray_T *gap, char_u *str)
{
    char_u	*res = str;
    char_u	numbuf[NUMBUFLEN];

    if (res == NULL)
	ga_concat(gap, (char_u *)"\"\"");
    else
    {
#if defined(FEAT_MBYTE) && defined(USE_ICONV)
	vimconv_T   conv;
	char_u	    *converted = NULL;

	if (!enc_utf8)
	{
	    /* Convert the text from 'encoding' to utf-8, the JSON string is
	     * always utf-8. */
	    conv.vc_type = CONV_NONE;
	    convert_setup(&conv, p_enc, (char_u*)"utf-8");
	    if (conv.vc_type != CONV_NONE)
		converted = res = string_convert(&conv, res, NULL);
	    convert_setup(&conv, NULL, NULL);
	}
#endif
	ga_append(gap, '"');
	while (*res != NUL)
	{
	    int c;
#ifdef FEAT_MBYTE
	    /* always use utf-8 encoding, ignore 'encoding' */
	    c = utf_ptr2char(res);
#else
	    c = *res;
#endif

	    switch (c)
	    {
		case 0x08:
		    ga_append(gap, '\\'); ga_append(gap, 'b'); break;
		case 0x09:
		    ga_append(gap, '\\'); ga_append(gap, 't'); break;
		case 0x0a:
		    ga_append(gap, '\\'); ga_append(gap, 'n'); break;
		case 0x0c:
		    ga_append(gap, '\\'); ga_append(gap, 'f'); break;
		case 0x0d:
		    ga_append(gap, '\\'); ga_append(gap, 'r'); break;
		case 0x22: /* " */
		case 0x5c: /* \ */
		    ga_append(gap, '\\');
		    ga_append(gap, c);
		    break;
		default:
		    if (c >= 0x20)
		    {
#ifdef FEAT_MBYTE
			numbuf[utf_char2bytes(c, numbuf)] = NUL;
#else
			numbuf[0] = c;
			numbuf[1] = NUL;
#endif
			ga_concat(gap, numbuf);
		    }
		    else
		    {
			vim_snprintf((char *)numbuf, NUMBUFLEN,
							 "\\u%04lx", (long)c);
			ga_concat(gap, numbuf);
		    }
	    }
#ifdef FEAT_MBYTE
	    res += utf_ptr2len(res);
#else
	    ++res;
#endif
	}
	ga_append(gap, '"');
#if defined(FEAT_MBYTE) && defined(USE_ICONV)
	vim_free(converted);
#endif
    }
}
コード例 #8
0
ファイル: json.c プロジェクト: KamarajuKusumanchi/vim
    static int
json_decode_string(js_read_T *reader, typval_T *res, int quote)
{
    garray_T    ga;
    int		len;
    char_u	*p;
    int		c;
    varnumber_T	nr;

    if (res != NULL)
	ga_init2(&ga, 1, 200);

    p = reader->js_buf + reader->js_used + 1; /* skip over " or ' */
    while (*p != quote)
    {
	/* The JSON is always expected to be utf-8, thus use utf functions
	 * here. The string is converted below if needed. */
	if (*p == NUL || p[1] == NUL
#ifdef FEAT_MBYTE
		|| utf_ptr2len(p) < utf_byte2len(*p)
#endif
		)
	{
	    /* Not enough bytes to make a character or end of the string. Get
	     * more if possible. */
	    if (reader->js_fill == NULL)
		break;
	    len = (int)(reader->js_end - p);
	    reader->js_used = (int)(p - reader->js_buf);
	    if (!reader->js_fill(reader))
		break; /* didn't get more */
	    p = reader->js_buf + reader->js_used;
	    reader->js_end = reader->js_buf + STRLEN(reader->js_buf);
	    continue;
	}

	if (*p == '\\')
	{
	    c = -1;
	    switch (p[1])
	    {
		case '\\': c = '\\'; break;
		case '"': c = '"'; break;
		case 'b': c = BS; break;
		case 't': c = TAB; break;
		case 'n': c = NL; break;
		case 'f': c = FF; break;
		case 'r': c = CAR; break;
		case 'u':
		    if (reader->js_fill != NULL
				     && (int)(reader->js_end - p) < NUMBUFLEN)
		    {
			reader->js_used = (int)(p - reader->js_buf);
			if (reader->js_fill(reader))
			{
			    p = reader->js_buf + reader->js_used;
			    reader->js_end = reader->js_buf
						     + STRLEN(reader->js_buf);
			}
		    }
		    nr = 0;
		    len = 0;
		    vim_str2nr(p + 2, NULL, &len,
				     STR2NR_HEX + STR2NR_FORCE, &nr, NULL, 4);
		    p += len + 2;
		    if (0xd800 <= nr && nr <= 0xdfff
			    && (int)(reader->js_end - p) >= 6
			    && *p == '\\' && *(p+1) == 'u')
		    {
			varnumber_T	nr2 = 0;

			/* decode surrogate pair: \ud812\u3456 */
			len = 0;
			vim_str2nr(p + 2, NULL, &len,
				     STR2NR_HEX + STR2NR_FORCE, &nr2, NULL, 4);
			if (0xdc00 <= nr2 && nr2 <= 0xdfff)
			{
			    p += len + 2;
			    nr = (((nr - 0xd800) << 10) |
				((nr2 - 0xdc00) & 0x3ff)) + 0x10000;
			}
		    }
		    if (res != NULL)
		    {
#ifdef FEAT_MBYTE
			char_u	buf[NUMBUFLEN];
			buf[utf_char2bytes((int)nr, buf)] = NUL;
			ga_concat(&ga, buf);
#else
			ga_append(&ga, (int)nr);
#endif
		    }
		    break;
		default:
		    /* not a special char, skip over \ */
		    ++p;
		    continue;
	    }
	    if (c > 0)
	    {
		p += 2;
		if (res != NULL)
		    ga_append(&ga, c);
	    }
	}
	else
	{
#ifdef FEAT_MBYTE
	    len = utf_ptr2len(p);
#else
	    len = 1;
#endif
	    if (res != NULL)
	    {
		if (ga_grow(&ga, len) == FAIL)
		{
		    ga_clear(&ga);
		    return FAIL;
		}
		mch_memmove((char *)ga.ga_data + ga.ga_len, p, (size_t)len);
		ga.ga_len += len;
	    }
	    p += len;
	}
    }

    reader->js_used = (int)(p - reader->js_buf);
    if (*p == quote)
    {
	++reader->js_used;
	if (res != NULL)
	{
	    ga_append(&ga, NUL);
	    res->v_type = VAR_STRING;
#if defined(FEAT_MBYTE) && defined(USE_ICONV)
	    if (!enc_utf8)
	    {
		vimconv_T   conv;

		/* Convert the utf-8 string to 'encoding'. */
		conv.vc_type = CONV_NONE;
		convert_setup(&conv, (char_u*)"utf-8", p_enc);
		if (conv.vc_type != CONV_NONE)
		{
		    res->vval.v_string =
				      string_convert(&conv, ga.ga_data, NULL);
		    vim_free(ga.ga_data);
		}
		convert_setup(&conv, NULL, NULL);
	    }
	    else
#endif
		res->vval.v_string = ga.ga_data;
	}
	return OK;
    }
    if (res != NULL)
    {
	res->v_type = VAR_SPECIAL;
	res->vval.v_number = VVAL_NONE;
	ga_clear(&ga);
    }
    return MAYBE;
}
コード例 #9
0
ファイル: digraph.c プロジェクト: AdnoC/neovim
/// Lookup the pair "char1", "char2" in the digraph tables.
///
/// @param char1
/// @param char2
/// @param meta_char
///
/// @return If no match, return "char2". If "meta_char" is TRUE and "char1"
//          is a space, return "char2" | 0x80.
static int getexactdigraph(int char1, int char2, int meta_char)
{
  int retval = 0;

  if (IS_SPECIAL(char1) || IS_SPECIAL(char2)) {
    return char2;
  }

  // Search user digraphs first.
  digr_T *dp = (digr_T *)user_digraphs.ga_data;
  for (int i = 0; i < user_digraphs.ga_len; ++i) {
    if (((int) dp->char1 == char1) && ((int) dp->char2 == char2)) {
      retval = dp->result;
      break;
    }
    ++dp;
  }

  // Search default digraphs.
  if (retval == 0) {
    dp = digraphdefault;

    for (int i = 0; dp->char1 != 0; ++i) {
      if (((int) dp->char1 == char1) && ((int) dp->char2 == char2)) {
        retval = dp->result;
        break;
      }
      ++dp;
    }
  }

  if ((retval != 0) && !enc_utf8) {
    char_u buf[6], *to;
    vimconv_T vc;

    // Convert the Unicode digraph to 'encoding'.
    int i = utf_char2bytes(retval, buf);
    retval = 0;
    vc.vc_type = CONV_NONE;

    if (convert_setup(&vc, (char_u *)"utf-8", p_enc) == OK) {
      vc.vc_fail = true;
      assert(i >= 0);
      size_t len = (size_t)i;
      to = string_convert(&vc, buf, &len);

      if (to != NULL) {
        retval = (*mb_ptr2char)(to);
        xfree(to);
      }
      (void)convert_setup(&vc, NULL, NULL);
    }
  }

  // Ignore multi-byte characters when not in multi-byte mode.
  if (!has_mbyte && (retval > 0xff)) {
    retval = 0;
  }

  if (retval == 0) {
    // digraph deleted or not found
    if ((char1 == ' ') && meta_char) {
      // <space> <char> --> meta-char
      return char2 | 0x80;
    }
    return char2;
  }
  return retval;
}
コード例 #10
0
ファイル: to_printable.hpp プロジェクト: doniexun/mettle
inline std::string to_printable(char32_t c) {
  return escape_string(string_convert(std::u32string(1, c)), '\'');
}
コード例 #11
0
ファイル: to_printable.hpp プロジェクト: doniexun/mettle
inline std::string to_printable(wchar_t c) {
  return escape_string(string_convert(std::wstring(1, c)), '\'');
}
コード例 #12
0
ファイル: to_printable.hpp プロジェクト: doniexun/mettle
inline std::string
to_printable(const METTLE_STRING_VIEW<Char, Traits> &s) {
  return escape_string(string_convert(s));
}
コード例 #13
0
ファイル: to_printable.hpp プロジェクト: doniexun/mettle
inline std::string
to_printable(const std::basic_string<Char, Traits, Alloc> &s) {
  return escape_string(string_convert(s));
}
コード例 #14
0
ファイル: to_printable.hpp プロジェクト: doniexun/mettle
inline std::string to_printable_boolish(const char32_t *s) {
  if(!s) return detail::null_str();
  return escape_string(string_convert(s));
}