C - qDecoder 7.1



宣告


#include "qDecoder.h"

int main(int argc, char **argv)
{
if (argc == 1 && qDecoder() > 0) {
qContentType("text/html");
qFreeAll();
} else {
/* command mode */
}
}

qDecoder() 初始化
qFree() or qFreeAll() 釋放

qContentType 常用參數:
text/html
text/css
text/javascript
text/xml
text/plain
application/json


基本抓值 - 定義


char *qValue(char *format, ...);
char *qValueDefault(char *defstr, char *format, ...);
int qiValue(char *format, ...);

基本抓值 - 用法


char *key1 = qValue("key1"); // 回傳 key1 的值,如果沒有定義 key1 則回傳 NULL
char *key2 = qValueDefault("defaultValue", "key2"); // 回傳 key2 的值,如果沒有定義 key2 則回傳字串 "defaultValue"
int val = qiValue("key3"); // 回傳 key3 的值,如果沒有定義 key3 則回傳 0



重覆抓值 - 定義


char *qValueFirst(char *format, ...);
char *qValueNext(void);

重覆抓值 - 用法

(用在參數是重覆的,如:key=str1&key=str2&key=str3...)

char *str;
for(str = qValueFirst("key"); str; str = qValueNext()) {
// 如範例,則變數 str 的值依序為 "str1""str2""str3"
}



增減參數值 - 定義


char *qValueAdd(char *name, char *format, ...);
void qValueRemove(char *format, ...);

增減參數值 - 用法


qValueAdd("key", "value"); // 增加參數key與值
qValueRemove("key"); // 刪除參數key與值



其他常用用法


int qCatFile(char *format, ...); // 印出檔案內容
int qDownload(char *filename); // 使用 http 標頭下載檔案
char *qStrReplace(char *mode, char *srcstr, char *tokstr, char *word); // 置換字串



qCatFile("檔案路徑及名稱")
qDownload("檔案路徑及名稱");

qStrReplace("模式", "來源字串", "要替換的標記字串", "新字串");
模式“tn”[t]oken 取代並將結果放入 [n]ew 陣列中。 (回傳新指標, 使用完需另外free)
模式“tr”[t]可以直接替換&[r]替換來源字串。 (回傳舊指標)
模式“sn”[s]字串替換並將結果放入[n]ew數組中。 (回傳新指標, 使用完需另外free)
模式“sr”[s]字串替換&[r]直接替換來源字串。 (回傳舊指標)





沒有留言:

張貼留言