Guitar
Static Public Member Functions | List of all members
misc Class Reference

#include <misc.h>

Static Public Member Functions

static int stricmp (char const *s1, char const *s2)
 
static int strnicmp (char const *s1, char const *s2, size_t n)
 
static QString getApplicationDir ()
 アプリケーションのディレクトリパスを取得する More...
 
static QStringList splitLines (QByteArray const &ba, std::function< QString(char const *ptr, size_t len)> const &tos)
 QByteArrayの文字列を行に分割する。 More...
 
static QStringList splitLines (QString const &text)
 文字列を行に分割する。 More...
 
static std::vector< std::string_view > splitLinesV (const std::string_view &str, bool keep_newline)
 文字列を行に分割する。 More...
 
static std::vector< std::string_view > splitLinesV (QByteArray const &ba, bool keep_newline)
 QByteArrayを行に分割する More...
 
static std::vector< std::string > splitLines (std::string_view const &str, bool keep_newline)
 文字列を行に分割する More...
 
static std::vector< std::string_view > splitWords (std::string_view const &text)
 文字列を単語に分割する More...
 
static QStringList splitWords (QString const &text)
 文字列を単語に分割する。 More...
 
static QString getFileName (QString const &path)
 パスからファイル名部分を取得する More...
 
static QString makeDateTimeString (const QDateTime &dt)
 日時を文字列に変換する More...
 
static bool starts_with (std::string const &str, std::string const &with)
 文字列が指定の文字列で始まるか判定する More...
 
static bool ends_with (std::string const &str, std::string const &with)
 文字列が指定の文字列で終わるか判定する More...
 
static std::string mid (std::string const &str, int start, int length=-1)
 文字列の一部分を取得する More...
 
static QString normalizePathSeparator (QString const &str)
 パスの区切り文字を正規化する More...
 
static QString joinWithSlash (QString const &left, QString const &right)
 2つのパスをスラッシュで結合する More...
 
static void setFixedSize (QWidget *w)
 ウィジェットのサイズを固定する More...
 
static void drawFrame (QPainter *pr, int x, int y, int w, int h, QColor color_topleft, QColor color_bottomright=QColor())
 矩形のフレームを描画する。 More...
 
static void dump (const uint8_t *ptr, size_t len)
 メモリダンプを16進数で表示する More...
 
static void dump (QByteArray const *in)
 バイナリデータの内容をヘキサでダンプする More...
 
static bool isText (std::string const &mimetype)
 MIMEタイプがテキストファイルを表すか判定する More...
 
static bool isImage (std::string const &mimetype)
 MIMEタイプが画像ファイルを表すか判定する More...
 
static bool isSVG (std::string const &mimetype)
 MIMEタイプがSVG画像を表すか判定する More...
 
static bool isPSD (std::string const &mimetype)
 MIMEタイプがPhotoshopファイルを表すか判定する More...
 
static bool isPDF (std::string const &mimetype)
 MIMEタイプがPDFファイルを表すか判定する More...
 
static QString abbrevBranchName (QString const &name)
 ブランチ名を短縮形に変換する。 More...
 
static std::string makeProxyServerURL (std::string text)
 プロキシサーバーURLを正規化する More...
 
static QString makeProxyServerURL (QString text)
 プロキシサーバーURLを正規化する More...
 
static QPoint contextMenuPos (QWidget *w, QContextMenuEvent *e)
 コンテキストメニューを表示する位置を計算する More...
 
static bool isExecutable (QString const &cmd)
 ファイルが実行可能か判定する More...
 
static QString collapseWhitespace (QString const &source)
 文字列内の連続する空白文字を1つのスペースにまとめる。 More...
 
static bool isValidMailAddress (const QString &email)
 文字列が有効なメールアドレスか判定する More...
 
static bool isValidMailAddress (std::string const &email)
 文字列が有効なメールアドレスか判定する More...
 
static std::string_view trimmed (std::string_view const &s)
 文字列の両端から空白文字を取り除く More...
 
static std::string_view trimQuotes (std::string_view s)
 文字列の両端から空白文字と引用符を取り除く More...
 
static std::string_view trimNewLines (std::string_view s)
 文字列の両端から改行文字を取り除く More...
 
static std::string bin_to_hex_string (const void *begin, const void *end)
 バイナリデータを16進数文字列に変換する More...
 
static std::vector< uint8_t > hex_string_to_bin (std::string_view const &s, const char *sep=nullptr)
 16進数文字列をバイナリデータに変換する More...
 
static int compare (uint8_t const *a, size_t n, uint8_t const *b, size_t m)
 2つのバイナリデータを比較する More...
 
static int compare (std::vector< uint8_t > const &a, std::vector< uint8_t > const &b)
 2つのバイトベクターを比較する More...
 
static std::vector< std::string > vector_string (std::vector< std::string_view > const &v)
 
template<typename T >
static T toi (std::string_view const &s, size_t *consumed=nullptr)
 

Member Function Documentation

◆ abbrevBranchName()

QString misc::abbrevBranchName ( QString const &  name)
static

ブランチ名を短縮形に変換する。

入力されたブランチ名を短縮形に変換します。ブランチ名の各パス要素の先頭文字を抽出し、 最後のパス要素を除いて短縮形にします。

Parameters
name短縮形に変換する対象のブランチ名。
Returns
短縮されたブランチ名。

◆ bin_to_hex_string()

std::string misc::bin_to_hex_string ( const void *  begin,
const void *  end 
)
static

バイナリデータを16進数文字列に変換する

バイナリデータ(バイト列)を16進数表記の文字列に変換します。 各バイトは2桁の16進数で表現されます(00-FF)。

Parameters
begin変換するバイナリデータの先頭ポインタ
end変換するバイナリデータの終端ポインタ(変換対象に含まれない)
Returns
16進数文字列

◆ collapseWhitespace()

QString misc::collapseWhitespace ( QString const &  source)
static

文字列内の連続する空白文字を1つのスペースにまとめる。

入力された文字列内の連続する空白文字を1つのスペースにまとめ、結果の文字列を返します。

Parameters
source連続する空白文字をまとめる対象のQStringオブジェクト。
Returns
連続する空白文字が1つのスペースにまとめられたQStringオブジェクト。

◆ compare() [1/2]

int misc::compare ( std::vector< uint8_t > const &  a,
std::vector< uint8_t > const &  b 
)
static

2つのバイトベクターを比較する

2つのバイトベクターを辞書的に比較します。 内部的にはcompare関数を使用して、ベクターの内容と長さを比較します。

Parameters
a比較する最初のバイトベクター
b比較する2番目のバイトベクター
Returns
a < b の場合は-1、a > b の場合は1、a == b の場合は0
Here is the call graph for this function:

◆ compare() [2/2]

int misc::compare ( uint8_t const *  a,
size_t  n,
uint8_t const *  b,
size_t  m 
)
static

2つのバイナリデータを比較する

2つのバイト配列を辞書的に比較します。最初に異なるバイトが見つかった時点で その大小関係を返します。同じバイト列で長さが異なる場合は、長い方が大きいと判定されます。

Parameters
a比較する最初のバイト配列
n最初の配列の長さ
b比較する2番目のバイト配列
m2番目の配列の長さ
Returns
a < b の場合は-1、a > b の場合は1、a == b の場合は0

◆ contextMenuPos()

QPoint misc::contextMenuPos ( QWidget *  w,
QContextMenuEvent *  e 
)
static

コンテキストメニューを表示する位置を計算する

コンテキストメニューイベントに基づいて、メニューを表示する適切な位置を計算します。 マウスによる右クリックの場合はカーソルの位置にオフセット(8,-8)を加え、 それ以外の場合(キーボードでの表示等)はウィジェットの左上から少し離れた位置(4,4)を返します。

Parameters
wコンテキストメニューを表示するウィジェット
eコンテキストメニューイベント
Returns
メニューを表示するグローバル座標位置

◆ drawFrame()

void misc::drawFrame ( QPainter *  pr,
int  x,
int  y,
int  w,
int  h,
QColor  color_topleft,
QColor  color_bottomright = QColor() 
)
static

矩形のフレームを描画する。

指定された位置とサイズの矩形のフレームを描画します。フレームの上辺と左辺は、 color_topleftで指定された色で描画され、右辺と下辺はcolor_bottomrightで指定された色で描画されます。

Parameters
prフレームを描画する対象のQPainterオブジェクトへのポインタ。
x矩形の左上隅のX座標。
y矩形の左上隅のY座標。
w矩形の幅。
h矩形の高さ。
color_topleftフレームの上辺と左辺の色。
color_bottomrightフレームの右辺と下辺の色。

◆ dump() [1/2]

void misc::dump ( const uint8_t *  ptr,
size_t  len 
)
static

メモリダンプを16進数で表示する

与えられたメモリ領域を16進数でダンプし、表示します。ダンプは、 アドレス、16進数データ(最大16バイトずつ)、ASCII文字列表現の3つの列で構成されます。 表示されない制御文字はピリオド(.)で表示されます。

Parameters
ptrダンプするメモリ領域の先頭ポインタ、nullptrの場合は何も表示しません
lenダンプするメモリ領域の長さ(バイト数)

◆ dump() [2/2]

void misc::dump ( QByteArray const *  in)
static

バイナリデータの内容をヘキサでダンプする

QByteArrayの内容をヘキサダンプ形式で表示します。 内部的にはdump(uint8_t const *, size_t)関数を使用して、 QByteArrayの内容をバイト配列としてダンプします。

Parameters
inダンプするQByteArrayへのポインタ、nullptrの場合は何も表示しません
Here is the call graph for this function:

◆ ends_with()

bool misc::ends_with ( std::string const &  str,
std::string const &  with 
)
static

文字列が指定の文字列で終わるか判定する

与えられた文字列が、指定された文字列で終わるかどうかを判定します。

Parameters
strチェックする対象の文字列
with終端に存在するか確認する文字列
Returns
終端がwithで終わる場合はtrue、そうでない場合はfalse

◆ getApplicationDir()

QString misc::getApplicationDir ( )
static

アプリケーションのディレクトリパスを取得する

実行可能ファイルが格納されているディレクトリのパスを返します。 Windowsの場合は'\'、Unixの場合は'/'をパス区切り文字として扱います。

Returns
アプリケーションのディレクトリパス

◆ getFileName()

QString misc::getFileName ( QString const &  path)
static

パスからファイル名部分を取得する

与えられたパスからファイル名部分のみを抽出します。

Parameters
pathファイル名を抽出する対象のパス
Returns
抽出されたファイル名

◆ hex_string_to_bin()

std::vector< uint8_t > misc::hex_string_to_bin ( std::string_view const &  s,
const char *  sep = nullptr 
)
static

16進数文字列をバイナリデータに変換する

16進数表記の文字列をバイナリデータ(バイト列)に変換します。 文字列には2桁の16進数表記(00-FF)を含める必要があります。 オプションで区切り文字を指定することもできます。

Parameters
s変換する16進数文字列
sep区切り文字の文字列。区切り文字はスキップされる。nullptrの場合は区切り文字なし
Returns
変換されたバイナリデータ

◆ isExecutable()

bool misc::isExecutable ( QString const &  cmd)
static

ファイルが実行可能か判定する

指定されたファイルパスが実行可能なファイルを指しているか判定します。

Parameters
cmd判定するファイルパス
Returns
実行可能な場合はtrue、そうでない場合はfalse

◆ isImage()

bool misc::isImage ( std::string const &  mimetype)
static

MIMEタイプが画像ファイルを表すか判定する

与えられたMIMEタイプが画像ファイルを表すか判定します。 PDFファイルや「image/」で始まる全てのMIMEタイプを画像として扱います。

Parameters
mimetype判定するMIMEタイプ文字列
Returns
画像ファイルを表す場合はtrue、そうでない場合はfalse
Here is the call graph for this function:

◆ isPDF()

bool misc::isPDF ( std::string const &  mimetype)
static

MIMEタイプがPDFファイルを表すか判定する

与えられたMIMEタイプがPDFファイルを表すか判定します。

Parameters
mimetype判定するMIMEタイプ文字列
Returns
PDFファイルを表す場合はtrue、そうでない場合はfalse

◆ isPSD()

bool misc::isPSD ( std::string const &  mimetype)
static

MIMEタイプがPhotoshopファイルを表すか判定する

与えられたMIMEタイプがAdobe Photoshopのファイルを表すか判定します。

Parameters
mimetype判定するMIMEタイプ文字列
Returns
Photoshopファイルを表す場合はtrue、そうでない場合はfalse

◆ isSVG()

bool misc::isSVG ( std::string const &  mimetype)
static

MIMEタイプがSVG画像を表すか判定する

与えられたMIMEタイプがSVG画像ファイルを表すか判定します。

Parameters
mimetype判定するMIMEタイプ文字列
Returns
SVG画像を表す場合はtrue、そうでない場合はfalse

◆ isText()

bool misc::isText ( std::string const &  mimetype)
static

MIMEタイプがテキストファイルを表すか判定する

与えられたMIMEタイプがテキストファイルを表すか判定します。

Parameters
mimetype判定するMIMEタイプ文字列
Returns
テキストファイルを表す場合はtrue、そうでない場合はfalse
Here is the call graph for this function:

◆ isValidMailAddress() [1/2]

bool misc::isValidMailAddress ( const QString &  email)
static

文字列が有効なメールアドレスか判定する

文字列が有効なメールアドレス形式かどうかを判定します。 単純に@記号が含まれており、先頭でも末尾でもないことを確認します。

Parameters
email検証するメールアドレス文字列
Returns
有効なメールアドレス形式の場合はtrue、そうでない場合はfalse

◆ isValidMailAddress() [2/2]

bool misc::isValidMailAddress ( std::string const &  email)
static

文字列が有効なメールアドレスか判定する

std::string形式の文字列が有効なメールアドレス形式かどうかを判定します。 内部的にはQString版のisValidMailAddressに変換して処理します。

Parameters
email検証するメールアドレス文字列
Returns
有効なメールアドレス形式の場合はtrue、そうでない場合はfalse
Here is the call graph for this function:

◆ joinWithSlash()

QString misc::joinWithSlash ( QString const &  left,
QString const &  right 
)
static

2つのパスをスラッシュで結合する

2つのパス文字列を適切な区切り文字を使用して結合します。 空の文字列が渡された場合は空でない方を返します。

Parameters
left左側のパス文字列
right右側のパス文字列
Returns
結合されたパス文字列
Here is the call graph for this function:

◆ makeDateTimeString()

QString misc::makeDateTimeString ( const QDateTime &  dt)
static

日時を文字列に変換する

日時情報を読みやすい文字列形式に変換します。 デフォルトではISOフォーマットを使用し、'T'を空白に置換します。

Parameters
dt変換する日時情報
Returns
変換された日時文字列。dt が無効な場合は空文字列

◆ makeProxyServerURL() [1/2]

QString misc::makeProxyServerURL ( QString  text)
static

プロキシサーバーURLを正規化する

入力されたプロキシサーバーのURLを正規化します。 プロトコルが指定されていない場合は "http://" を付加し、 末尾にスラッシュがない場合は付加します。

Parameters
text正規化するプロキシサーバーURL文字列
Returns
正規化されたプロキシサーバーURL

◆ makeProxyServerURL() [2/2]

std::string misc::makeProxyServerURL ( std::string  text)
static

プロキシサーバーURLを正規化する

入力されたプロキシサーバーのURLを正規化します。 プロトコルが指定されていない場合は "http://" を付加し、 末尾にスラッシュがない場合は付加します。

Parameters
text正規化するプロキシサーバーURL文字列
Returns
正規化されたプロキシサーバーURL

◆ mid()

std::string misc::mid ( std::string const &  str,
int  start,
int  length = -1 
)
static

文字列の一部分を取得する

与えられた文字列の指定位置から、指定された長さの部分文字列を抽出します。

Parameters
str対象の文字列
start抽出を開始する位置のインデックス
length抽出する文字の数。負の場合は文字列の最後まで抽出する
Returns
抽出された部分文字列

◆ normalizePathSeparator()

QString misc::normalizePathSeparator ( QString const &  s)
static

パスの区切り文字を正規化する

パスの区切り文字をプラットフォームに合わせて正規化します。 Windowsでは '/' を '\' に変換し、 Unix系プラットフォームでは変換を行いません。

Parameters
str正規化するパス文字列
Returns
正規化されたパス文字列

◆ setFixedSize()

void misc::setFixedSize ( QWidget *  w)
static

ウィジェットのサイズを固定する

ウィジェットのサイズを固定し、リサイズできないようにします。 また、コンテキストヘルプボタンを非表示にし、Windowsの固定サイズダイアログヒントを設定します。

Parameters
wサイズを固定する対象のウィジェット

◆ splitLines() [1/3]

QStringList misc::splitLines ( QByteArray const &  ba,
std::function< QString(char const *ptr, size_t len)> const &  tos 
)
static

QByteArrayの文字列を行に分割する。

与えられたQByteArrayの文字列を行に分割し、QStringListとして返します。 分割は、改行文字 ('
' または '\r
') を区切りとして行われます。 また、与えられた変換関数を使用して、charの配列をQStringに変換します。

Parameters
ba分割する対象のQByteArray。
tos文字列を変換する関数。charの配列とその長さを引数に取り、QStringを返す関数。
Returns
分割された行のリスト。
Here is the call graph for this function:

◆ splitLines() [2/3]

QStringList misc::splitLines ( QString const &  text)
static

文字列を行に分割する。

与えられた文字列を行に分割し、QStringListとして返します。 分割は、改行文字 ('
' または '\r
') を区切りとして行われます。

Parameters
text分割する対象の文字列。
Returns
分割された行のリスト。

◆ splitLines() [3/3]

std::vector< std::string > misc::splitLines ( std::string_view const &  str,
bool  keep_newline 
)
static

文字列を行に分割する

与えられた文字列を行に分割し、std::stringのベクターとして返します。

Parameters
str分割する対象の文字列
keep_newline改行文字を含めて行を格納する場合はtrue、そうでない場合はfalse
Returns
分割された行のリスト
Here is the call graph for this function:

◆ splitLinesV() [1/2]

std::vector< std::string_view > misc::splitLinesV ( const std::string_view &  str,
bool  keep_newline 
)
static

文字列を行に分割する。

与えられた文字列を行に分割し、std::vector<std::string>として返します。 分割は、改行文字 ('
' または '\r
') を区切りとして行われます。

Parameters
str分割する対象の文字列。
[out]out分割された行を格納するstd::vectorへのポインタ。
keep_newline改行文字を含めて行を格納する場合はtrue、そうでない場合はfalse。

◆ splitLinesV() [2/2]

std::vector< std::string_view > misc::splitLinesV ( QByteArray const &  ba,
bool  keep_newline 
)
static

QByteArrayを行に分割する

QByteArrayの内容を文字列として行に分割し、std::string_viewのベクターとして返します。

Parameters
ba分割する対象のQByteArray
keep_newline改行文字を含めて行を格納する場合はtrue、そうでない場合はfalse
Returns
分割された行のリスト
Here is the call graph for this function:

◆ splitWords() [1/2]

QStringList misc::splitWords ( QString const &  text)
static

文字列を単語に分割する。

与えられた文字列を単語に分割し、QStringListとして返します。分割は、空白文字を 区切りとして行われます。

Parameters
text分割する対象の文字列。
Returns
分割された単語のリスト。

◆ splitWords() [2/2]

std::vector< std::string_view > misc::splitWords ( std::string_view const &  text)
static

文字列を単語に分割する

与えられた文字列を単語に分割し、std::string_viewのベクターとして返します。 分割は、空白文字を区切りとして行われます。

Parameters
text分割する対象の文字列
Returns
分割された単語のリスト

◆ starts_with()

bool misc::starts_with ( std::string const &  str,
std::string const &  with 
)
static

文字列が指定の文字列で始まるか判定する

与えられた文字列が、指定された文字列で始まるかどうかを判定します。

Parameters
strチェックする対象の文字列
with先頭に存在するか確認する文字列
Returns
先頭がwithで始まる場合はtrue、そうでない場合はfalse

◆ stricmp()

static int misc::stricmp ( char const *  s1,
char const *  s2 
)
inlinestatic

◆ strnicmp()

static int misc::strnicmp ( char const *  s1,
char const *  s2,
size_t  n 
)
inlinestatic

◆ toi()

template<typename T >
static T misc::toi ( std::string_view const &  s,
size_t *  consumed = nullptr 
)
inlinestatic

◆ trimmed()

std::string_view misc::trimmed ( std::string_view const &  s)
static

文字列の両端から空白文字を取り除く

文字列の先頭と末尾から空白文字(スペース、タブ、改行など)を削除します。 元の文字列は変更せず、新しいstring_viewを返します。

Parameters
sトリムする文字列
Returns
両端の空白が削除された文字列ビュー

◆ trimNewLines()

std::string_view misc::trimNewLines ( std::string_view  s)
static

文字列の両端から改行文字を取り除く

文字列の先頭と末尾から改行文字(CR、LF、CRLF)を削除します。 元の文字列は変更せず、新しいstring_viewを返します。 CR+LFの組み合わせは1つの改行として扱われます。

Parameters
sトリムする文字列
Returns
両端の改行が削除された文字列ビュー

◆ trimQuotes()

std::string_view misc::trimQuotes ( std::string_view  s)
static

文字列の両端から空白文字と引用符を取り除く

文字列の先頭と末尾から空白文字を削除し、その後引用符('"'または'\'')で囲まれている場合は それらの引用符も削除します。元の文字列は変更せず、新しいstring_viewを返します。

Parameters
sトリムする文字列
Returns
両端の空白と引用符が削除された文字列ビュー
Here is the call graph for this function:

◆ vector_string()

static std::vector<std::string> misc::vector_string ( std::vector< std::string_view > const &  v)
inlinestatic

The documentation for this class was generated from the following files: