- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- ソース を表示
- PostgreSQL/開発/include/lib/stringinfo.h へ行く。
- 1 (2017-05-14 (日) 23:54:49)
- 2 (2017-05-14 (日) 23:59:51)
- 3 (2017-05-15 (月) 19:53:53)
- 4 (2017-05-16 (火) 00:08:52)
概要 †
- 文字列操作のための機能
定義 †
マクロ †
appendStringInfoCharMacro †
appendStringInfoCharMacro(str,ch)
列挙型 †
構造体 †
StringInfoData †
StringInfoは,StringInfoDataポインタの別名である
StringInfoData strdata; initStringInfo(&strdata); appendStringInfoCharMacro(&strdata, 'A'); elog(NOTICE, "%s", strdata.data);
番号 | データ型 | フィールド | 説明 |
---|---|---|---|
1 | char* | data | 文字列データのポインタ |
2 | int | len | 文字列の長さ(\0終端) |
3 | int | maxlen | バッファ割り当ての最大長 |
4 | int | cursor | 文字列バッファのカーソル,makeStringInfoやinitStringInfoで0初期化される。 stringinfo.cルーチンの中で都度更新されるフィールドでない |
関数 †
makeStringInfo †
typedef StringInfoData *StringInfo;
- StringInfoDataを初期化してポインタを返す
サンプル
// 引数1: extern StringInfo makeStringInfo(void);
initStringInfo †
StringInfo *strinfo = makeStringInfo();
- StringInfoを初期化する,makeStringInfo()の中で呼ばれる
サンプル
// 引数1:StringInfo構造体(StringInfoDataのポインタ) extern void initStringInfo(StringInfo str);
resetStringInfo †
StringInfo strinfo = (StringInfo) palloc(sizeof(StringInfoData)); initStringInfo(strinfo);
- バッファ領域はそのままで0初期化される
appendStringInfo †
// 引数1:StringInfo構造体(StringInfoDataのポインタ) extern void resetStringInfo(StringInfo str);
- strバッファの末尾に文字列を追加する
- バッファ領域が不足している場合は拡張される
サンプル
// 引数1:StringInfo構造体(StringInfoDataのポインタ) // 引数2〜:strに追加する文字列のフォーマット指定子と追加する文字列 extern void appendStringInfo(StringInfo str, const char *fmt,...) pg_attribute_printf(2, 3);
appendStringInfoVA †
StringInfo strinfo = makeStringInfo(); appendStringInfo(strinfo, "%s", "hoge"); elog(NOTICE, "%s", strinfo->data);
- strのバッファ領域に文字列を追加する,
- 戻り値が0でない場合は,既存の文字列はそのままで追加に必要な見積もりサイズを返す
appendStringInfoString †
// 引数1:StringInfo構造体(StringInfoDataのポインタ) // 引数2〜:strに追加する文字列のフォーマット指定子と追加する文字列 // 引数3:追加する文字列の可変長引数 // 戻り値:=0:書き込み成功,≠0 追加に必要とされる領域サイズ extern int appendStringInfoVA(StringInfo str, const char *fmt, va_list args) pg_attribute_printf(2, 0);
- strのバッファ領域に文字列を追加する
- バッファ領域が不足している場合は拡張される
- memcpyでコピーする
appendStringInfoChar †
// 引数1:StringInfo構造体(StringInfoDataのポインタ) // 引数2:追加する文字列 extern void appendStringInfoString(StringInfo str, const char *s);
- strのバッファ領域に単一バイト文字を追加する
appendStringInfoSpaces †
// 引数1:StringInfo構造体(StringInfoDataのポインタ) // 引数2:追加する文字(シングルバイト) extern void appendStringInfoChar(StringInfo str, char ch);
- strのバッファ領域に指定された数分のスペースを追加する
appendBinaryStringInfo †
// 引数1:StringInfo構造体(StringInfoDataのポインタ) // 引数2:追加するスペースサイズ extern void appendStringInfoSpaces(StringInfo str, int count);
- strのバッファ領域にdataポインタで示される領域のdatalenサイズ分のデータをコピーする
- appendStringInfoString()関数内で呼ばれる
enlargeStringInfo †
// 引数1:引数1:StringInfo構造体(StringInfoDataのポインタ) // 引数2:追加する文字列 // 引数3:文字列のサイズ extern void appendBinaryStringInfo(StringInfo str, const char *data, int datalen);
- strのバッファ領域をneededバイト分拡張する
サンプルプログラム †
// 引数1:引数1:StringInfo構造体(StringInfoDataのポインタ) // 引数2:拡張するサイズ(バイト) extern void enlargeStringInfo(StringInfo str, int needed);
参考・関連 †
- stringinfo.h - on doxygen.postgresql.org