LAPTOP-SNT8I5JK\Boounion
2024-12-12 016703bb359382dc1de4ac204da47b6f29c55c81
SourceCode/Bond/BondEq/RegexEdit.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,74 @@
#if !defined(AFX_REGEXEDIT_H__A4EABEC5_2E8C_11D1_B79F_00805F9ECE10__INCLUDED_)
#define AFX_REGEXEDIT_H__A4EABEC5_2E8C_11D1_B79F_00805F9ECE10__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include <afxwin.h>
#include <regex>
#include <functional>
#include <limits>
// æžšä¸¾ç±»åž‹ï¼šæ­£åˆ™è¡¨è¾¾å¼ç±»åž‹
enum class RegexType
{
    Alphanumeric,   // å…è®¸å­—母和数字
    Letters,        // åªå…è®¸å­—母
    Digits,         // åªå…è®¸æ•°å­—
    Decimal,        // å…è®¸å°æ•°å’Œæ•´æ•°
    Custom          // è‡ªå®šä¹‰æ­£åˆ™
};
class CRegexEdit : public CEdit
{
    DECLARE_DYNAMIC(CRegexEdit)
public:
    // æž„造与析构
    CRegexEdit();
    virtual ~CRegexEdit();
    // è®¾ç½®æ­£åˆ™ç±»åž‹
    void SetRegexType(RegexType enType);
    // è®¾ç½®è‡ªå®šä¹‰æ­£åˆ™è¡¨è¾¾å¼
    void SetCustomRegex(const std::string& strCustomRegex);
    // è®¾ç½®æ•°å€¼èŒƒå›´ï¼ˆæ•´æ•°æˆ–浮点)
    void SetValueRange(long double dMinValue, long double dMaxValue);
    // è®¾ç½®è‡ªå®šä¹‰æ¯”较函数
    void SetCustomComparator(std::function<bool(const std::string&)> comparator);
   // è®¾ç½®è¾“入不合法函数
    void SetInvalidInputCallback(std::function<void()> callback);
    // æŸ¥æ‰¾åŒ¹é…å†…容
    bool FindMatch(const std::string& pattern, std::string& foundText);
    // æ›¿æ¢åŒ¹é…å†…容
    void ReplaceMatch(const std::string& pattern, const std::string& replacement);
protected:
    // æ ¹æ®æžšä¸¾å€¼è¿”回对应的正则表达式
    std::regex GetCurrentRegex() const;
    // æ ¡éªŒè¾“入是否在指定范围内
    bool IsValueInRange(const std::string& strText);
protected:
    RegexType m_enRegexType;        // å½“前选中的正则类型
    std::string m_strCustomRegex;   // è‡ªå®šä¹‰æ­£åˆ™è¡¨è¾¾å¼
   long double m_dMinValue;        // æœ€å°å€¼
   long double m_dMaxValue;      // æœ€å¤§å€¼
   std::function<bool(const std::string&)> m_customComparator; // è‡ªå®šä¹‰æ¯”较函数
    std::function<void()> m_invalidInputCallback;               // ä¸åˆæ³•输入的回调函数
protected:
    void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
    DECLARE_MESSAGE_MAP()
};
#endif // !defined(AFX_REGEXEDIT_H__A4EABEC5_2E8C_11D1_B79F_00805F9ECE10__INCLUDED_)