⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regext.c

📁 PHP v6.0 For Linux 运行环境:Win9X/ WinME/ WinNT/ Win2K/ WinXP
💻 C
字号:
/**********************************************************************  regext.c -  Oniguruma (regular expression library)**********************************************************************//*- * Copyright (c) 2002-2005  K.Kosako  <sndgk393 AT ybb DOT ne DOT jp> * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#include "regint.h"static voidconv_ext0be32(const UChar* s, const UChar* end, UChar* conv){  while (s < end) {    *conv++ = '\0';    *conv++ = '\0';    *conv++ = '\0';    *conv++ = *s++;  }}static voidconv_ext0le32(const UChar* s, const UChar* end, UChar* conv){  while (s < end) {    *conv++ = *s++;    *conv++ = '\0';    *conv++ = '\0';    *conv++ = '\0';  }}static voidconv_ext0be(const UChar* s, const UChar* end, UChar* conv){  while (s < end) {    *conv++ = '\0';    *conv++ = *s++;  }}static voidconv_ext0le(const UChar* s, const UChar* end, UChar* conv){  while (s < end) {    *conv++ = *s++;    *conv++ = '\0';  }}static voidconv_swap4bytes(const UChar* s, const UChar* end, UChar* conv){  while (s < end) {    *conv++ = s[3];    *conv++ = s[2];    *conv++ = s[1];    *conv++ = s[0];    s += 4;  }}static voidconv_swap2bytes(const UChar* s, const UChar* end, UChar* conv){  while (s < end) {    *conv++ = s[1];    *conv++ = s[0];    s += 2;  }}static intconv_encoding(OnigEncoding from, OnigEncoding to, const UChar* s, const UChar* end,              UChar** conv, UChar** conv_end){  int len = end - s;  if (to == ONIG_ENCODING_UTF16_BE) {    if (from == ONIG_ENCODING_ASCII || from == ONIG_ENCODING_ISO_8859_1) {      *conv = (UChar* )xmalloc(len * 2);      CHECK_NULL_RETURN_VAL(*conv, ONIGERR_MEMORY);      *conv_end = *conv + (len * 2);      conv_ext0be(s, end, *conv);      return 0;    }    else if (from == ONIG_ENCODING_UTF16_LE) {    swap16:      *conv = (UChar* )xmalloc(len);      CHECK_NULL_RETURN_VAL(*conv, ONIGERR_MEMORY);      *conv_end = *conv + len;      conv_swap2bytes(s, end, *conv);      return 0;    }  }  else if (to == ONIG_ENCODING_UTF16_LE) {    if (from == ONIG_ENCODING_ASCII || from == ONIG_ENCODING_ISO_8859_1) {      *conv = (UChar* )xmalloc(len * 2);      CHECK_NULL_RETURN_VAL(*conv, ONIGERR_MEMORY);      *conv_end = *conv + (len * 2);      conv_ext0le(s, end, *conv);      return 0;    }    else if (from == ONIG_ENCODING_UTF16_BE) {      goto swap16;    }  }  if (to == ONIG_ENCODING_UTF32_BE) {    if (from == ONIG_ENCODING_ASCII || from == ONIG_ENCODING_ISO_8859_1) {      *conv = (UChar* )xmalloc(len * 4);      CHECK_NULL_RETURN_VAL(*conv, ONIGERR_MEMORY);      *conv_end = *conv + (len * 4);      conv_ext0be32(s, end, *conv);      return 0;    }    else if (from == ONIG_ENCODING_UTF32_LE) {    swap32:      *conv = (UChar* )xmalloc(len);      CHECK_NULL_RETURN_VAL(*conv, ONIGERR_MEMORY);      *conv_end = *conv + len;      conv_swap4bytes(s, end, *conv);      return 0;    }  }  else if (to == ONIG_ENCODING_UTF32_LE) {    if (from == ONIG_ENCODING_ASCII || from == ONIG_ENCODING_ISO_8859_1) {      *conv = (UChar* )xmalloc(len * 4);      CHECK_NULL_RETURN_VAL(*conv, ONIGERR_MEMORY);      *conv_end = *conv + (len * 4);      conv_ext0le32(s, end, *conv);      return 0;    }    else if (from == ONIG_ENCODING_UTF32_BE) {      goto swap32;    }  }  return ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION;}extern intonig_new_deluxe(regex_t** reg, const UChar* pattern, const UChar* pattern_end,                OnigCompileInfo* ci, OnigErrorInfo* einfo){  int r;  UChar *cpat, *cpat_end;  if (IS_NOT_NULL(einfo)) einfo->par = (UChar* )NULL;  if (ci->pattern_enc != ci->target_enc) {    r = conv_encoding(ci->pattern_enc, ci->target_enc, pattern, pattern_end,                      &cpat, &cpat_end);    if (r) return r;  }  else {    cpat     = (UChar* )pattern;    cpat_end = (UChar* )pattern_end;  }  r = onig_alloc_init(reg, ci->option, ci->ambig_flag, ci->target_enc,                      ci->syntax);  if (r) goto err;  r = onig_compile(*reg, cpat, cpat_end, einfo);  if (r) {    onig_free(*reg);    *reg = NULL;  } err:  if (cpat != pattern) xfree(cpat);  return r;}extern intonig_recompile_deluxe(regex_t* reg, const UChar* pattern, const UChar* pattern_end,                      OnigCompileInfo* ci, OnigErrorInfo* einfo){  int r;  regex_t *new_reg;  r = onig_new_deluxe(&new_reg, pattern, pattern_end, ci, einfo);  if (r) return r;  if (ONIG_STATE(reg) == ONIG_STATE_NORMAL) {    onig_transfer(reg, new_reg);  }  else {    onig_chain_link_add(reg, new_reg);  }  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -