Annotation of nono/lib/mystring.h, revision 1.1.1.8

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
1.1.1.6   root        7: //
                      8: // 文字列操作
                      9: //
                     10: 
1.1       root       11: #pragma once
                     12: 
1.1.1.3   root       13: #include "header.h"
1.1.1.4   root       14: #include <vector>
1.1.1.3   root       15: 
1.1       root       16: extern std::string string_format(const char *fmt, ...) __printflike(1, 2);
1.1.1.2   root       17: 
                     18: // 先頭の連続する空白文字列を取り除いた新しい文字列を返す
                     19: extern std::string string_ltrim(const std::string& str);
                     20: 
                     21: // 末尾の連続する空白文字列を取り除く
                     22: extern void string_rtrim(std::string& str);
                     23: 
                     24: // 末尾の連続する空白文字列を取り除く (char *版)
                     25: extern void rtrim(char *str);
                     26: 
1.1.1.5   root       27: // 文字列 str から先頭と末尾の連続する空白文字を取り除いた新しい文字列を返す。
                     28: extern std::string string_trim(const std::string& str);
                     29: 
1.1.1.7   root       30: // 文字列中の ASCII 大文字を小文字に、小文字を大文字にした新しい文字列を返す。
1.1.1.2   root       31: extern std::string string_tolower(const std::string& str);
1.1.1.7   root       32: extern std::string string_toupper(const std::string& str);
1.1.1.4   root       33: 
                     34: // 文字列 lhs の先頭が rhs と大文字小文字の区別なしで一致すれば true を返す。
                     35: // ASCII 専用。
                     36: extern bool
                     37: starts_with_ignorecase(const std::string& lhs, const std::string& rhs);
                     38: 
                     39: // 文字列 str (長さ len) を文字 c で分割したリストを返す
                     40: // (実際には以下2つのどちらかを呼ぶことになるはず)。
                     41: //
                     42: // str に c が含まれてなければ str 全体が1つの要素。
                     43: // c が str の先頭あるいは末尾にあれば、先頭(末尾) に空要素が出来る。
                     44: // 連続する c は同一の区切りとはみなさない。
                     45: // c は ',' のようなのを想定している。
1.1.1.5   root       46: // nlimit は戻り値リストの最大要素数で、0 なら指定なし。
                     47: extern std::vector<std::string> string_split(const char *str, int len, char c,
                     48:        int nlimit = 0);
1.1.1.4   root       49: 
                     50: // 文字列 str を文字 c で分割したリストを返す。
1.1.1.5   root       51: static inline std::vector<std::string> string_split(const char *str, char c,
                     52:        int nlimit = 0) {
                     53:        return string_split(str, strlen(str), c, nlimit);
1.1.1.4   root       54: }
                     55: // 文字列 str を文字 c で分割したリストを返す。
                     56: static inline std::vector<std::string> string_split(const std::string& str,
1.1.1.5   root       57:                char c, int nlimit = 0) {
                     58:        return string_split(str.c_str(), str.size(), c, nlimit);
1.1.1.4   root       59: }
1.1.1.6   root       60: 
                     61: // val を3桁ずつカンマ区切りした文字列にして返す。
                     62: extern std::string format_number(uint64 val);
1.1.1.7   root       63: 
                     64: // val を width 桁ゼロ埋めした 16進数文字列にして返す。
                     65: extern std::string strhex(uint32 val, int width = 8);
1.1.1.8 ! root       66: 
        !            67: // 経過時刻 t を文字列にして返す。(フル版)
        !            68: extern const std::string TimeToStr(uint64 t);
        !            69: // 経過時刻 t を文字列にして返す。(10秒未満のみの短縮版)
        !            70: extern const std::string SecToStr(uint64 t);

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.