Skip to content

Commit

Permalink
ArticleBase: Add member function that ReplaceStr applies to subject
Browse files Browse the repository at this point in the history
スレタイトルに文字列置換を適用する`ArticleBase::get_modified_subject()`
を追加します。
置換したスレタイトルはキャッシュされて再び呼び出されたときに返します。
また、キャッシュの有無に関係なく置換を行うように指定する引数も実装します。

Co-authored-by: JD Project <jd.project@acc574344b8506f1335297eaa7f74be0f7ea992b>
  • Loading branch information
ma8ma and JD Project committed Aug 20, 2022
1 parent 1614414 commit 33c8158
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
28 changes: 26 additions & 2 deletions src/dbtree/articlebase.cpp
Expand Up @@ -19,11 +19,12 @@

#include "config/globalconf.h"

#include "httpcode.h"
#include "command.h"
#include "cache.h"
#include "command.h"
#include "global.h"
#include "httpcode.h"
#include "login2ch.h"
#include "replacestrmanager.h"
#include "session.h"
#include "updatemanager.h"

Expand Down Expand Up @@ -423,6 +424,29 @@ void ArticleBase::reset_status()
}


/** @brief 置換文字列を適用したスレタイトルを返す
*
* @details
* 置換したスレタイトルはキャッシュされて再び呼び出されたときに返す。
* @param[in] renew true のときキャッシュの有無に関係なく置換文字列を適用して更新する
*/
const std::string& ArticleBase::get_modified_subject( const bool renew )
{
if( renew || m_modified_subject.empty() ){
const CORE::ReplaceStr_Manager* const mgr = CORE::get_replacestr_manager();

// タイトル文字列置換
if( mgr->list_get_active( CORE::REPLACETARGET_SUBJECT ) ){
m_modified_subject = mgr->replace( m_subject, CORE::REPLACETARGET_SUBJECT );
}
else m_modified_subject = m_subject;

}

return m_modified_subject;
}


void ArticleBase::set_subject( const std::string& subject )
{
if( subject.empty() ) return;
Expand Down
2 changes: 2 additions & 0 deletions src/dbtree/articlebase.h
Expand Up @@ -52,6 +52,7 @@ namespace DBTREE
std::string m_org_host;

std::string m_subject; // サブジェクト
std::string m_modified_subject; // 置換で変更されたサブジェクト
int m_number{}; // サーバ上にあるレスの数
int m_number_diff{}; // レス増分( subject.txt をロードした時の m_number の増分 )
int m_number_new{}; // 新着数( ロードした時の差分読み込み数)
Expand Down Expand Up @@ -143,6 +144,7 @@ namespace DBTREE
const std::string& get_id() const { return m_id; }
const std::string& get_key() const { return m_key; }
const std::string& get_subject() const { return m_subject; }
const std::string& get_modified_subject( const bool renew = false );
int get_number() const noexcept { return m_number; }
int get_number_diff() const noexcept { return m_number_diff; }
int get_number_new() const noexcept { return m_number_new; }
Expand Down
6 changes: 5 additions & 1 deletion src/dbtree/interface.cpp
Expand Up @@ -928,11 +928,15 @@ std::string DBTREE::article_ext_err( const std::string& url )
return DBTREE::get_article( url )->get_ext_err();
}

std::string DBTREE::article_subject( const std::string& url )
const std::string& DBTREE::article_subject( const std::string& url )
{
return DBTREE::get_article( url )->get_subject();
}

const std::string& DBTREE::article_modified_subject( const std::string& url, const bool renew )
{
return DBTREE::get_article( url )->get_modified_subject( renew );
}

int DBTREE::article_number( const std::string& url )
{
Expand Down
3 changes: 2 additions & 1 deletion src/dbtree/interface.h
Expand Up @@ -227,7 +227,8 @@ namespace DBTREE
int article_code( const std::string& url );
std::string article_str_code( const std::string& url );
std::string article_ext_err( const std::string& url );
std::string article_subject( const std::string& url );
const std::string& article_subject( const std::string& url );
const std::string& article_modified_subject( const std::string& url, const bool renew = false );
int article_number( const std::string& url );
int article_number_load( const std::string& url );
int article_number_seen( const std::string& url );
Expand Down

0 comments on commit 33c8158

Please sign in to comment.