/* ** 2013-05-15 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ****************************************************************************** ** ** This SQLite extension implements a rot13() function and a rot13 ** collating sequence. */ #include "sqlite3ext.h" SQLITE_EXTENSION_INIT1 #include #include /* ** Perform rot13 encoding on a single ASCII character. */ static unsigned char rot13(unsigned char c){ if( c>='a' && c<='z' ){ c += 13; if( c>'z' ) c -= 26; }else if( c>='A' && c<='Z' ){ c += 13; if( c>'Z' ) c -= 26; } return c; } /* ** Implementation of the rot13() function. ** ** Rotate ASCII alphabetic characters by 13 character positions. ** Non-ASCII characters are unchanged. rot13(rot13(X)) should always ** equal X. */ static void rot13func( sqlite3_context *context, int argc, sqlite3_value **argv ){ const unsigned char *zIn; int nIn; unsigned char *zOut; unsigned char *zToFree = 0; int i; unsigned char zTemp[100]; assert( argc==1 ); if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; zIn = (const unsigned char*)sqlite3_value_text(argv[0]); nIn = sqlite3_value_bytes(argv[0]); if( nIn