Слияние кода завершено, страница обновится автоматически
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_Inflector.h"
zend_class_entry * inflector_ce;
/* {{{ ARG_INFO
*/
ZEND_BEGIN_ARG_INFO_EX(inflector_underscore_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, camelCase)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(inflector_camelize_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, underscored)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(inflector_variable_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, underscored)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(inflector_humanize_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, underscored)
ZEND_END_ARG_INFO()
/* }}} */
/* applePie => apple_pie */
PHP_METHOD(Inflector, underscore) {
int len;
char *camelCase = NULL, *rtn = NULL, *p;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s", &camelCase, &len) == FAILURE){
RETURN_NULL();
}
if(len==0){
RETURN_NULL();
}
rtn = (char*) emalloc(2 * len + 1);
memset((void*) rtn, '\0', 2 * len + 1);
p = rtn;
while(*camelCase){
if(*camelCase >= 0x41 && *camelCase <= 0x5A){
*p++ = '_';
*p++ = *camelCase + 32;
}else{
*p++ = *camelCase;
}
camelCase++ ;
}
RETURN_STRING(rtn, 0);
}
PHP_METHOD(Inflector, camelize){
int len;
char *underscored = NULL, *p = NULL, *s=NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s", &underscored, &len) == FAILURE){
RETURN_NULL();
}
if(len <= 0){
RETURN_NULL();
}
p = s = underscored;
if(*p >= 0x61 && *p <= 0x7A){
*p -= 32;
}
while(*p){
if( *p == '_'){
if(*(p+1)>=0x61 && *(p+1)<=0x7A){
*(p+1) -= 32;
}
}else{
*s++ = *p;
}
p++;
}
*s='\0';
RETURN_STRING(underscored, 1);
}
PHP_METHOD(Inflector, variable){
int len;
char *underscored = NULL, *p = NULL, *s=NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"s", &underscored, &len) == FAILURE){
RETURN_NULL();
}
if(len <= 0){
RETURN_NULL();
}
p = s = underscored;
while(*p){
if( *p == '_'){
if(*(p+1)>=0x61 && *(p+1)<=0x7A){
*(p+1) -= 32;
}
}else{
*s++ = *p;
}
p++;
}
*s='\0';
RETURN_STRING(underscored, 1);
}
PHP_METHOD(Inflector, humanize){
int len;
char *underscored = NULL, *p=NULL, *s=NULL, *rtn = NULL;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &underscored, &len) == FAILURE){
RETURN_NULL();
}
if(len == 0){
RETURN_NULL();
}
rtn = (char*) emalloc(len*2+1);
memset((void *)rtn, '\0', len*2+1);
s = rtn ;
p=underscored;
if(*p >= 0x61 && *p<=0x7A){
*p = *p - 32;
}
while(*p){
if('_' == *p){
*s++ = ' ';
if(*(p+1)>=0x61 && *(p+1)<=0x7A){
*(p+1) = *(p+1) - 32;
}
}else{
*s++ = *p;
}
p++;
}
*s = '\0';
RETURN_STRING(rtn, 0);
}
/* If you declare any globals in php_Inflector.h uncomment this:
ZEND_DECLARE_MODULE_GLOBALS(Inflector)
*/
/* True global resources - no need for thread safety here */
static int le_Inflector;
/* {{{ Inflector_functions[]
*
* Every user visible function must have an entry in Inflector_functions[].
*/
const zend_function_entry Inflector_functions[] = {
PHP_FE(confirm_Inflector_compiled, NULL) /* For testing, remove later. */
{NULL, NULL, NULL} /* Must be the last line in Inflector_functions[] */
};
/* }}} */
/* {{{ Inflector_module_entry
*/
zend_module_entry Inflector_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
"Inflector",
Inflector_functions,
PHP_MINIT(Inflector),
PHP_MSHUTDOWN(Inflector),
PHP_RINIT(Inflector), /* Replace with NULL if there's nothing to do at request start */
PHP_RSHUTDOWN(Inflector), /* Replace with NULL if there's nothing to do at request end */
PHP_MINFO(Inflector),
#if ZEND_MODULE_API_NO >= 20010901
"0.1", /* Replace with version number for your extension */
#endif
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_INFLECTOR
ZEND_GET_MODULE(Inflector)
#endif
/* {{{ PHP_INI
*/
/* Remove comments and fill if you need to have entries in php.ini
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("Inflector.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_Inflector_globals, Inflector_globals)
STD_PHP_INI_ENTRY("Inflector.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_Inflector_globals, Inflector_globals)
PHP_INI_END()
*/
/* }}} */
/* {{{ php_Inflector_init_globals
*/
/* Uncomment this function if you have INI entries
static void php_Inflector_init_globals(zend_Inflector_globals *Inflector_globals)
{
Inflector_globals->global_value = 0;
Inflector_globals->global_string = NULL;
}
*/
/* }}} */
zend_function_entry Inflector_methods[] = {
PHP_ME(Inflector, underscore, inflector_underscore_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Inflector, camelize, inflector_camelize_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Inflector, variable, inflector_camelize_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(Inflector, humanize, inflector_humanize_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
{NULL, NULL, NULL}
};
void inflector_declare_property_plural(){
zval *rules, *uninflected, *irregular, *plural;
MAKE_STD_ZVAL(rules);
MAKE_STD_ZVAL(uninflected);
MAKE_STD_ZVAL(irregular);
MAKE_STD_ZVAL(plural);
array_init_size(rules, 21);
add_assoc_stringl_ex(rules, ZEND_STRS("/(s)tatus$/i"), ZEND_STRL("\\1\\2tatuses"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/(quiz)$/i"), ZEND_STRL("\\1zes"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/^(ox)$/i"), ZEND_STRL("\\1\\2en"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/([m|l])ouse$/i"), ZEND_STRL("\\1ice"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/(matr|vert|ind)(ix|ex)$/i"), ZEND_STRL("\\1ices"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/(x|ch|ss|sh)$/i"), ZEND_STRL("\\1es"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/([^aeiouy]|qu)y$/i"), ZEND_STRL("\\1ies"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/(hive)$/i"), ZEND_STRL("\\1s"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/(?:([^f])fe|([lr])f)$/i"), ZEND_STRL("\\1\\2ves"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/sis$/i"), ZEND_STRL("ses"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/([ti])um$/i"), ZEND_STRL("\\1a"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/(p)erson$/i"), ZEND_STRL("\\1eople"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/(m)an$/i"), ZEND_STRL("\\1en"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/(c)hild$/i"), ZEND_STRL("\\1hildren"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/(buffal|tomat)o$/i"), ZEND_STRL("\\1\\2oes"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i"), ZEND_STRL("\\1i"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/us$/i"), ZEND_STRL("uses"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/(alias)$/i"), ZEND_STRL("\\1es"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/(ax|cris|test)is$/i"), ZEND_STRL("\\1es"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/s$/"), ZEND_STRL("s"), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/^$/"), ZEND_STRL(""), 1);
add_assoc_stringl_ex(rules, ZEND_STRS("/$/"), ZEND_STRL("s"), 1);
array_init(uninflected);
add_next_index_stringl(uninflected, ZEND_STRL(".*[nrlm]ese"), 1);
add_next_index_stringl(uninflected, ZEND_STRL(".*deer"), 1);
add_next_index_stringl(uninflected, ZEND_STRL(".*fish"), 1);
add_next_index_stringl(uninflected, ZEND_STRL(".*measles"), 1);
add_next_index_stringl(uninflected, ZEND_STRL(".*ois"), 1);
add_next_index_stringl(uninflected, ZEND_STRL(".*pox"), 1);
add_next_index_stringl(uninflected, ZEND_STRL(".*sheep"), 1);
add_next_index_stringl(uninflected, ZEND_STRL("people"), 1);
array_init_size(irregular, 31);
add_assoc_stringl_ex(irregular, ZEND_STRS("atlas"), ZEND_STRL("atlases"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("beef"), ZEND_STRL("beefs"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("brother"), ZEND_STRL("brothers"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("cafe"), ZEND_STRL("cafes"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("child"), ZEND_STRL("children"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("cookie"), ZEND_STRL("cookies"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("corpus"), ZEND_STRL("corpuses"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("cow"), ZEND_STRL("cows"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("ganglion"), ZEND_STRL("ganglions"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("genie"), ZEND_STRL("genies"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("genus"), ZEND_STRL("genera"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("graffito"), ZEND_STRL("graffiti"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("hoof"), ZEND_STRL("hoofs"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("loaf"), ZEND_STRL("loaves"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("man"), ZEND_STRL("men"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("money"), ZEND_STRL("monies"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("mongoose"), ZEND_STRL("mongooses"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("move"), ZEND_STRL("moves"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("mythos"), ZEND_STRL("mythoi"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("niche"), ZEND_STRL("niches"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("numen"), ZEND_STRL("numina"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("occiput"), ZEND_STRL("occiputs"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("octopus"), ZEND_STRL("octopuses"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("opus"), ZEND_STRL("opuses"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("ox"), ZEND_STRL("oxen"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("penis"), ZEND_STRL("penises"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("person"), ZEND_STRL("people"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("sex"), ZEND_STRL("sexes"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("soliloquy"), ZEND_STRL("soliloquies"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("testis"), ZEND_STRL("testes"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("trilby"), ZEND_STRL("trilbys"), 1);
add_assoc_stringl_ex(irregular, ZEND_STRS("turf"), ZEND_STRL("turfs"), 1);
array_init(plural);
add_assoc_zval_ex(plural, ZEND_STRS("rules"), rules);
add_assoc_zval_ex(plural, ZEND_STRS("irregular"), irregular);
add_assoc_zval_ex(plural, ZEND_STRS("uninflected"), uninflected);
zend_declare_class_constant(inflector_ce, ZEND_STRL("_plural"), plural TSRMLS_DC);
// zend_declare_property_null(inflector_ce, ZEND_STRL("_plural"), ZEND_ACC_STATIC | ZEND_ACC_PUBLIC TSRMLS_CC);
// zend_update_static_property(inflector_ce, ZEND_STRL("_plural"), plural TSRMLS_DC);
}
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(Inflector)
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "Inflector", Inflector_methods);
inflector_ce = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
inflector_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
zend_declare_class_constant_long(inflector_ce, ZEND_STRL("TestConstant"), 100 TSRMLS_DC);
// inflector_declare_property_plural();
/* If you have INI entries, uncomment these lines
REGISTER_INI_ENTRIES();
*/
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MSHUTDOWN_FUNCTION
*/
PHP_MSHUTDOWN_FUNCTION(Inflector)
{
/* uncomment this line if you have INI entries
UNREGISTER_INI_ENTRIES();
*/
return SUCCESS;
}
/* }}} */
/* Remove if there's nothing to do at request start */
/* {{{ PHP_RINIT_FUNCTION
*/
PHP_RINIT_FUNCTION(Inflector)
{
return SUCCESS;
}
/* }}} */
/* Remove if there's nothing to do at request end */
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
PHP_RSHUTDOWN_FUNCTION(Inflector)
{
return SUCCESS;
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(Inflector)
{
php_info_print_table_start();
php_info_print_table_header(2, "Inflector support", "enabled");
php_info_print_table_end();
/* Remove comments if you have entries in php.ini
DISPLAY_INI_ENTRIES();
*/
}
/* }}} */
/* Remove the following function when you have succesfully modified config.m4
so that your module can be compiled into PHP, it exists only for testing
purposes. */
/* Every user-visible function in PHP should document itself in the source */
/* {{{ proto string confirm_Inflector_compiled(string arg)
Return a string to confirm that the module is compiled in */
PHP_FUNCTION(confirm_Inflector_compiled)
{
char *arg = NULL;
int arg_len, len;
char *strg;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
return;
}
len = spprintf(&strg, 0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "Inflector", arg);
RETURN_STRINGL(strg, len, 0);
}
/* }}} */
/* The previous line is meant for vim and emacs, so it can correctly fold and
unfold functions in source code. See the corresponding marks just before
function definition, where the functions purpose is also documented. Please
follow this convention for the convenience of others editing your code.
*/
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )