显示标签为“VS”的博文。显示所有博文
显示标签为“VS”的博文。显示所有博文

2007年9月27日星期四

QT4 和 VS2005 SP1 编译错误 C2244

Author : sanchaji2
Article ID : 94
Audience : Default
Version 1.00
Published Date: 2007/8/7 6:49:30
Reads : 32
一个BUG的修正,可能引入更多BUG的出现不仅仅是教科书上的套话。今天,我在重新编译QT商业版源代码时,就遇到了这样的一个例子。VS2005安装 SP1补丁后,编译QT4源代码(QT v4.2.2版),编译器报告很多模板方面的致命错误,导致编译失败。通过查询网络可知,这是SP1引入的BUG,微软已经发布了修正补丁,您可以在 http://support.microsoft.com/kb/930198 找到详细信息,另外,微软给出了该错误的详细描述,请参考 http://support.microsoft.com/kb/928957

我解决这个问题是通过修改配置文件,使 QT 系统调用 INTEL C++ Compiler 来编译代码避开这个BUG。如果您坚持希望通过MSVC 2005 SP1编译QT源代码,请安装上面提及的补丁,或者参考 thought 的 文章 修改QT源代码。

下面附上,我这里用到的 bin\qtvars.bat,如果您有微软的 KB930198 补丁,希望您能发送到我的电子邮箱 12985462 at QQ dot com ,谢谢!
下面再附上,一份QT与VS2005-SP1的兼容性修正补丁,不用自己修改了!


@echo off
rem
rem This file is generated
rem

echo Setting up a Qt environment...
echo -- QTDIR set to C:\Qt\4.2.2
echo -- Added C:\Qt\4.2.2\bin to PATH
echo -- QMAKESPEC set to win32-icc

set QTDIR=C:\Qt\4.2.2
set PATH=C:\Qt\4.2.2\bin;%PATH%
set QMAKESPEC=win32-icc

if not "%1"=="vsvars" goto END
call "E:\Program Files\Intel\Compiler\C++\9.1\IA32\Bin\ICLVars.bat"
:END

if not "%1"=="vsstart" goto ENDSTARTVS
call "E:\Program Files\Intel\Compiler\C++\9.1\IA32\Bin\ICLVars.bat"
devenv /useenv
:ENDSTARTVS


下面这份修正补丁来自日本一个专门说明这一问题的博客网页: http://ashula.info/mt/d061216_qt4_msvc8_sp1_problem.html


下载: qt4-multi-map-hash-msvc8-sp1.diff
diff -Naur tools_orig/qhash.h tools/qhash.h
--- tools_orig/qhash.h 2006-12-17 03:53:53.406250000 +0900
+++ tools/qhash.h 2006-12-17 05:16:20.921875000 +0900
@@ -848,8 +848,11 @@
QMultiHash() {}
QMultiHash(const QHash &other) : QHash(other) {}

- inline typename QHash::iterator replace(const Key &key, const T &value);
- inline typename QHash::iterator insert(const Key &key, const T &value);
+ // fix for vs2005 SP1
+ // cf. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=987536&SiteID=1
+ typedef QHash::iterator QHashItr;
+ inline typename QHashItr replace(const Key &key, const T &value);
+ inline typename QHashItr insert(const Key &key, const T &value);

inline QMultiHash &operator+=(const QMultiHash &other)
{ unite(other); return *this; }
@@ -862,11 +865,11 @@
};

template
-Q_INLINE_TEMPLATE Q_TYPENAME QHash::iterator QMultiHash::replace(const Key &akey, const T &avalue)
+Q_INLINE_TEMPLATE Q_TYPENAME QMultiHash::QHashItr QMultiHash::replace(const Key &akey, const T &avalue)
{ return QHash::insert(akey, avalue); }

template
-Q_INLINE_TEMPLATE Q_TYPENAME QHash::iterator QMultiHash::insert(const Key &akey, const T &avalue)
+Q_INLINE_TEMPLATE Q_TYPENAME QMultiHash::QHashItr QMultiHash::insert(const Key &akey, const T &avalue)
{ return QHash::insertMulti(akey, avalue); }


diff -Naur tools_orig/qmap.h tools/qmap.h
--- tools_orig/qmap.h 2006-12-17 03:53:03.437500000 +0900
+++ tools/qmap.h 2006-12-17 05:16:29.984375000 +0900
@@ -890,8 +890,11 @@
QMultiMap() {}
QMultiMap(const QMap &other) : QMap(other) {}

- inline typename QMap::iterator replace(const Key &key, const T &value);
- inline typename QMap::iterator insert(const Key &key, const T &value);
+ // fix for vs2005 SP1
+ // cf. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=987536&SiteID=1
+ typedef QMap::iterator QMapItr;
+ inline typename QMapItr replace( const Key &key, const T &value );
+ inline typename QMapItr insert( const Key &key, const T &value );

inline QMultiMap &operator+=(const QMultiMap &other)
{ unite(other); return *this; }
@@ -904,11 +907,11 @@
};

template
-Q_INLINE_TEMPLATE Q_TYPENAME QMap::iterator QMultiMap::replace(const Key &akey, const T &avalue)
+Q_INLINE_TEMPLATE Q_TYPENAME QMultiMap::QMapItr QMultiMap::replace(const Key &akey, const T &avalue)
{ return QMap::insert(akey, avalue); }

template
-Q_INLINE_TEMPLATE Q_TYPENAME QMap::iterator QMultiMap::insert(const Key &akey, const T &avalue)
+Q_INLINE_TEMPLATE Q_TYPENAME QMultiMap::QMapItr QMultiMap::insert(const Key &akey, const T &avalue)
{ return QMap::insertMulti(akey, avalue); }

解决Visual Studio 2005 SP1编译QT代码的BUG

解决Visual Studio 2005 SP1编译QT代码的BUG

产品:QT 4.1.4 & QT 4.2.2
平台:Visual Studio 2005 Service Pack 1 (SP1)
错误:error C2244: unable to match function definition to an existing declaration

现象:
在qmap.h头文件中出现:error C2244: 'QMultiMap::insert' : unable to match function definition to an existing declaration
(据说在qhash.h中也会出现)

参考URL:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=214100

原因:编译器升级后,分不清嵌套类型的名字是指哪一个,哪怕它们很明显地是同一个类型。例如,如下代码就会引发此错误:

template
class Foo
{
public:
typedef int NestedType;
};

template
class Bar : public Foo
{
public:
typename Foo::NestedType test();
};

template
typename Foo::NestedType Bar::test() // this is where the error lies
{
return 0;
}

微软的解释:
The problem is due to the use of Foo and Bar on the line above; the compiler cannot figure out the relationship between the two template parameters even though they are clearly the same. The workaround is to add a typedef for the NestedType of Bar and use that in the implementation of test

解决方法:
在子类型中再次定义嵌套类型的名字

例如,对于QMultiMap,就是这样子

template
class QMultiMap : public QMap
{
public:
/////////////////////////////////////////////////////////////////////////
//Modified by Kenny
//Purpose: fixed the compiling-time error of Visual Studio 2005 SP1
//Ref:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=214100
typedef typename QMap::iterator QMapIteratorType;
//End of modification
/////////////////////////////////////////////////////////////////////////
QMultiMap() {}
QMultiMap(const QMap &other) : QMap(other) {}

inline QMapIteratorType replace(const Key &key, const T &value);
inline QMapIteratorType insert(const Key &key, const T &value);

inline QMultiMap &operator+=(const QMultiMap &other)
{ unite(other); return *this; }
inline QMultiMap operator+(const QMultiMap &other) const
{ QMultiMap result = *this; result += other; return result; }

private:
T &operator[](const Key &key);
const T operator[](const Key &key) const;
};

/////////////////////////////////////////////////////////////////////////////
//Modified by Kenny
//Purpose: fixed the compiling-time error of Visual Studio 2005 SP1
//Ref:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=214100
template
Q_INLINE_TEMPLATE Q_TYPENAME QMultiMap::QMapIteratorType QMultiMap::replace(const Key &akey, const T &avalue)
{ return QMap::insert(akey, avalue); }

template
Q_INLINE_TEMPLATE Q_TYPENAME QMultiMap::QMapIteratorType QMultiMap::insert(const Key &akey, const T &avalue)
{ return QMap::insertMulti(akey, avalue); }

//The old code is commented out as the following lines

//template
//Q_INLINE_TEMPLATE Q_TYPENAME QMap::iterator QMultiMap::replace(const Key &akey, const T &avalue)
//{ return QMap::insert(akey, avalue); }
//
//template
//Q_INLINE_TEMPLATE Q_TYPENAME QMap::iterator QMultiMap::insert(const Key &akey, const T &avalue)
//{ return QMap::insertMulti(akey, avalue); }

//End of modification
/////////////////////////////////////////////////////////////////////////////

2007年9月21日星期五

好用的 CopySourceAsHtml,我的中文修正版

CopySourceAsHtml 是個很棒的工具,可用來輔助製作程式文件。它是一個 Visual Studio 的 add-in,安裝好之後,只要在 VS2005 的編輯畫面中點滑鼠右鍵,再選「Copy As HTML...」,就能將選取的程式碼轉成 HTML 並複製到剪貼簿。這對於製作程式文件、在網站上分享程式碼來說,真是很方便的工具。

可惜的是,我使用之後發現中文字無法正確處理;精確的說,應該是無法正確處理 Unicode 字元。因此我自己動手將這個部份的 bugs 修正了(開放原碼萬歲!)。為了示範成果,我將自己的類別庫中的字串工具類別貼上來,附在文後。需要這個修正版的朋友,可以直接下載附件回去,然後照以下步驟進行:

  1. 下載 CopySourceAsHtml 2.0.0 Installer。直接執行裡面的安裝程式即可(安裝前請先關閉 VS2005) 。
  2. 將本文附件的壓縮檔解開,把裡面的 bin\ 目錄下的 CopySourceAsHtml.dll 和 CopySourceAsHtml.pdb 覆蓋掉原本安裝的檔案。原本這兩個檔案是安裝在本機的 Documents and Settings\<USER>\My Documents\Visual Studio 2005\Addins\ 目錄下。
  3. 完成!開啟 VS2005 測試看看:開啟一個程式檔,選取文字,點右鍵,「Copy As HTML...」,再貼到某個網頁中看看轉出來的結果。

要特別說明的是,在修正 bug 時,主要是處理 RTF 字串的剖析,由於這部分我還是第一次處理,因此是一邊看 RTF spec,一邊寫單元測試來逐一測試各種中文字的編碼情況。不保證 100% 沒問題喔!若您有發現問題,可回應此文,或者您也可以自己動手修改,完整原始碼我都附上了(只要搜尋關鍵字 "Tsai" 就能找到我修改的部份)。

2006-10-24 更新:

使用 Visual Studio 2005 中文版的朋友還必須修正 Connect.cs,可參考 Hikari 提供的修正:

  194             commandBars = (CommandBars)this.application.CommandBars;

  195             editPopup = (CommandBarPopup)commandBars["MenuBar"].Controls["編輯(&E)"];

  196

  197             copyIndex = FindCopyOnCommandBar("編輯(&E)") + 1;

感謝 Hikari!
註:這部份的修改若能改成支援多國語言的方式,以自動支援兩種版本的 VS2005,就更好了。若有人有興趣修改,可參考 Connect.cs 中的 "Resource.*" 的程式碼,以及 Resources.resx 的內容。改完的話希望也能寄一份給我,功德無量 :)

============================================================

以下是我的字串工具類別,有些地方顯示成表情圖案,是因為程式碼剛好與此部落格的表情圖案碼相同

    1 using System;
    2 using System.Text;
    3 using System.Text.RegularExpressions;
    4 using System.Web;
    5 using System.Security.Cryptography;
    6 
    7 namespace Huanlin.Helpers
    8 {
    9     /// <summary>
   10     /// 字串處理工具類別。
   11     /// </summary>
   12     public sealed class StrHelper
   13     {
   14         private StrHelper()
   15         {
   16         }
   17 
   18         /// <summary>
   19         /// Append a slash character '\' to string.
   20         /// </summary>
   21         /// <param name="input">輸入字串。</param>
   22         /// <returns>輸出字串。</returns>
   23         public static string AppendSlash(string input)
   24         {
   25             if (input == null)
   26                     return @"\";
   27             if (input.EndsWith("/") || input.EndsWith("\\"))
   28                 return input;
   29             return input + "\\";
   30         }
   31 
   32         /// <summary>
   33         /// Remove the last slash character.
   34         /// </summary>
   35         /// <param name="input">輸入字串。</param>
   36         /// <returns>輸出字串。</returns>
   37         public static string RemoveLastSlash(string input)
   38         {
   39             if (input == null)
   40                 return "";
   41             if (input.EndsWith("/") || input.EndsWith("\\"))
   42                 return input.Remove(input.Length-1, 1);
   43             return input;
   44         }
   45 
   46         /// <summary>
   47         /// 移除任何一個指定的字元。
   48         /// </summary>
   49         /// <param name="input">輸入字串。</param>
   50         /// <param name="anyOf">要移除的字元。</param>
   51         /// <returns>輸出字串。</returns>
   52         public static string RemoveAny(string input, char[] anyOf)
   53         {
   54             if (String.IsNullOrEmpty(input))
   55                 return input;
   56 
   57             int i;
   58             while (true)
   59             {
   60                 i = input.IndexOfAny(anyOf);
   61                 if (i < 0)
   62                     break;
   63                 input = input.Remove(i, 1);
   64             }
   65             return input;
   66         }
   67 
   68         /// <summary>
   69         /// 移除換行字元(\n) 和(\r)。
   70         /// </summary>
   71         /// <param name="input">輸入字串。</param>
   72         /// <returns>輸出字串。</returns>
   73         public static string RemoveNewLines(string input)
   74         {
   75             return StrHelper.RemoveNewLines(input, false);
   76         }
   77 
   78         /// <summary>
   79         /// 移除換行字元(\n) 和(\r)。
   80         /// </summary>
   81         /// <param name="input">輸入字串。</param>
   82         /// <param name="addSpace">若為true,則把換行符號替換成空白字元。</param>
   83         /// <returns>輸出字串。</returns>
   84         public static string RemoveNewLines(string input,
   85            bool addSpace)
   86         {
   87             string replace = string.Empty;
   88             if (addSpace)
   89                 replace = " ";
   90 
   91             string pattern = @"[\r|\n]";
   92             Regex regEx = new Regex(pattern, RegexOptions.Multiline);
   93 
   94             return regEx.Replace(input, replace);
   95         }
   96 
   97         /// <summary>
   98         /// 移除空白字元(包括全形空白)。
   99         /// </summary>
  100         /// <param name="input">輸入字串。</param>
  101         /// <param name="fullShapeSpaces">是否連全形空白也一併刪除。</param>
  102         /// <returns>輸出字串。</returns>
  103         public static string RemoveSpaces(string input, bool fullShapeSpaces)
  104         {
  105             string replace = string.Empty;
  106             string pattern = @"[ ]";
  107             if (fullShapeSpaces)
  108             {
  109                 pattern = @"[ | ]";
  110             }                
  111 
  112             Regex regEx = new Regex(pattern, RegexOptions.Multiline);
  113 
  114             return regEx.Replace(input, replace);
  115         }
  116 
  117 
  118         /// <summary>
  119         /// 檢驗身分證號碼的正確性。
  120         ///    驗證規則:
  121         ///
  122         ///        身份證統一編號共計有10 位,其中第一位為英文字母,後共有九個數字;
  123         ///        而最後一位數字為檢查碼( Check Digit ) ,表示如下表:
  124         ///
  125         ///        L1 D2 D2 D3 D4 D5 D6 D7 D8 D9 
  126         ///
  127         ///        L1: 英文字母, 代表出生地的縣/市代號
  128         ///        D2: 性別,1=男, 2=女
  129         ///        D9: 檢查碼
  130         ///
  131         ///        L1 對照表:
  132         ///
  133         ///          字母A  B  C  D  E  F  G  H  J  K  L  M  N 
  134         ///          代號10 11 12 13 14 15 16 17 18 19 20 21 22 
  135         ///          -------------------------------------------
  136         ///          字母P  Q  R  S  T  U  V  X  Y  W  Z  I  O
  137         ///          代號23 24 25 26 27 28 29 30 31 32 33 34 35 
  138         ///
  139         ///        令其十位數為X1 ,個位數為X2 ;( 如A:X1=1 , X2=0 )
  140         ///
  141         ///        依其公式計算結果:
  142         ///        Y= X1 + 9*X2 + 8*D1 + 7*D2 + 6*D3 + 5*D4 + 4*D5 + 3*D6 + 2*D7 + 
  143         ///        D8 + D9
  144         ///
  145         ///      假如Y能被10 整除,則表示該身份證號碼為正確,否則為錯誤。即如以10 為
  146         ///        模數,檢查號碼為( 10 - Y- D9 ) / 10 的餘數,如餘數為0 時,則檢查碼
  147         ///        為0 。
  148         /// 
  149         /// </summary>
  150         /// <param name="input"></param>
  151         /// <returns></returns>
  152         public static bool CheckIdno(string idno) 
  153         {
  154             int[] letter_weight = 
  155             {
  156                 // A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R
  157                 10, 11, 12, 13, 14, 15, 16, 17, 34, 18, 19, 20, 21, 22, 35, 23, 24, 25,
  158                 26, 27, 28, 29, 32, 30, 31, 33
  159                 // S   T   U   V   W   X   Y   Z
  160             };
  161 
  162             int  i;
  163             int[] D = new int[9];    // 1..9
  164             int sum;
  165 
  166             if (idno.Length != 10)
  167                 return false;
  168             idno = idno.ToUpper();
  169             if (!Char.IsLetter(idno[0]) || (idno[1] != '1' && idno[1] != '2')) 
  170                 return false;
  171             for (i = 1; i < 10; i++)
  172             {
  173                 if (!Char.IsDigit(idno, i))
  174                     return false;
  175             }
  176 
  177             for (i = 0; i < 9; i++) // 1..9
  178             {
  179                 DIdea = Int32.Parse(idno.Substring(i+1, 1));
  180             }
  181 
  182             i = letter_weight[idno[0]-'A'];
  183             sum = (i / 10) + (i % 10) * 9;
  184             sum = sum + 8 * D[0] + 7 * D[1] + 6 * D[2] + 5 * D[3]
  185                 + 4 * D[4] + 3 * D[5] + 2 * D[Devil + D[7] + D[Music;
  186             return (sum % 10 == 0);
  187         }
  188 
  189         /// <summary>
  190         /// 判斷字串值是否為數字。
  191         /// </summary>
  192         /// <param name="input"></param>
  193         /// <returns></returns>
  194         public static bool IsDigit(string s)
  195         {
  196             try
  197             {
  198                 long num = Convert.ToInt64(s);
  199                 return true;
  200             }
  201             catch
  202             {
  203                 return false;
  204             }
  205         }
  206 
  207         /// <summary>
  208         /// 將字串轉成位元組陣列。
  209         /// </summary>
  210         /// <param name="str"></param>
  211         /// <returns></returns>
  212         public static byte[] StrToByteArray(string str)
  213         {
  214             System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
  215             return encoding.GetBytes(str);
  216         }
  217 
  218         /// <summary>
  219         /// 將字串轉成位元組陣列。
  220         /// </summary>
  221         /// <param name="str">輸入字串。</param>
  222         /// <param name="enc">編碼。</param>
  223         /// <returns></returns>
  224         public static byte[] StrToByteArray(string str, Encoding enc)
  225         {
  226             return enc.GetBytes(str);
  227         }
  228 
  229         /// <summary>
  230         /// Byte 陣列轉成字串。
  231         /// </summary>
  232         /// <param name="bytes"></param>
  233         /// <returns></returns>
  234         public static string ByteArrayToStr(byte[] bytes)
  235         {
  236             System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
  237             return enc.GetString(bytes);
  238         }
  239 
  240         /// <summary>
  241         /// 大小寫無關的置換函式。
  242         /// </summary>
  243         /// <param name="input">輸入字串。</param>
  244         /// <param name="newValue">要被置換的字串。</param>
  245         /// <param name="oldValue">置換的新字串。</param>
  246         /// <returns>A string</returns>
  247         public static string CaseInsenstiveReplace(string input,
  248            string oldValue, string newValue)
  249         {
  250             Regex regEx = new Regex(oldValue,
  251                RegexOptions.IgnoreCase | RegexOptions.Multiline);
  252             return regEx.Replace(input, newValue);
  253         }
  254 
  255         /// <summary>
  256         /// 檢查傳入的字串是否有出現任何一個指定的字串。字串比對時有分大小寫。
  257         /// </summary>
  258         /// <param name="input">欲檢查的字串</param>
  259         /// <param name="hasWords">要搜尋的字詞。</param>
  260         /// <returns>有符合的字詞</returns>
  261         public static MatchCollection HasWords(string input,
  262            params string[] hasWords)
  263         {
  264             StringBuilder sb = new StringBuilder(hasWords.Length + 50);
  265             //sb.Append("[");
  266 
  267             foreach (string s in hasWords)
  268             {
  269                 sb.AppendFormat("({0})|",
  270                    HttpUtility.HtmlEncode(s.Trim()));
  271             }
  272 
  273             string pattern = sb.ToString();
  274             pattern = pattern.TrimEnd('|'); // +"]";
  275 
  276             Regex regEx = new Regex(pattern, RegexOptions.Multiline);
  277             return regEx.Matches(input);
  278         }
  279 
  280         /// <summary>
  281         /// 將字串以MD5 編碼。
  282         /// </summary>
  283         /// <param name="input">欲編碼的字串。</param>
  284         /// <returns>編碼過的字串</returns>
  285         public static string MD5Encode(string input)
  286         {
  287             // Create a new instance of the 
  288             // MD5CryptoServiceProvider object.
  289             MD5 md5Hasher = MD5.Create();
  290 
  291             // Convert the input string to a byte 
  292             // array and compute the hash.
  293             byte[] data=http://anonymouse.org/cgi-bin/anon-www.cgi/http://huanlin.dyndns.org/cs/blogs/huan-lins_blog/archive/2006/10/20/md5Hasher.ComputeHash(
  294                Encoding.Default.GetBytes(input));
  295 
  296             // Create a new Stringbuilder to collect the bytes
  297             // and create a string.
  298             StringBuilder sBuilder = new StringBuilder();
  299 
  300             // Loop through each byte of the hashed data 
  301             // and format each one as a hexadecimal string.
  302             for (int i = 0; i < data.Length; i++)
  303             {
  304                 sBuilder.Append(dataIdea.ToString("x2"));
  305             }
  306 
  307             // Return the hexadecimal string.
  308             return sBuilder.ToString();
  309         }
  310 
  311         /// <summary>
  312         /// 刪除空白以及多餘的結束字元('\0')。
  313         /// 某些WinAPI 傳回的字元陣列轉成字串之後,後面會附加結束字元和垃圾資料,便可使用此函式。
  314         /// </summary>
  315         /// <param name="input">輸入字串</param>
  316         /// <returns>輸出字串。</returns>
  317         public static string Trim(string s)
  318         {
  319             s = s.Trim();
  320             int i = s.IndexOf('\0');
  321             if (i >= 0)
  322             {
  323                 return s.Substring(0, i);
  324             }
  325             return s;
  326         }
  327 
  328         /// <summary>
  329         /// 驗證一個字串是否經過MD5 編碼後會與傳入的MD5 字串相符。可用來驗證使用者密碼。
  330         /// </summary>
  331         /// <param name="input">欲比較的字串。</param>
  332         /// <param name="hash">MD5 編碼過的字串。</param>
  333         /// <returns>若相符則傳回True,否則傳回False。</returns>
  334         public static bool MD5Verify(string input, string md5str)
  335         {
  336             // Hash the input.
  337             string hashOfInput = StrHelper.MD5Encode(input);
  338 
  339             // Create a StringComparer an comare the hashes.
  340             StringComparer comparer = StringComparer.OrdinalIgnoreCase;
  341 
  342             if (0 == comparer.Compare(hashOfInput, md5str))
  343             {
  344                 return true;
  345             }
  346             else
  347             {
  348                 return false;
  349             }
  350         }
  351 
  352         /// <summary>
  353         /// 將字串中的所有全形空白轉成半形空白。
  354         /// </summary>
  355         /// <param name="input">輸入字串。</param>
  356         /// <returns>輸出字串。</returns>
  357         public static string FullShapeSpaceToSpace(string input)
  358         {
  359             string replace = " ";
  360             string pattern = @"[ ]";
  361             Regex regEx = new Regex(pattern, RegexOptions.Multiline);
  362             return regEx.Replace(input, replace);
  363         }
  364 
  365         /// <summary>
  366         /// 把所有空白字元轉換成HTML 空白。
  367         /// </summary>
  368         /// <param name="input">輸入字串。</param>
  369         /// <returns>輸出字串。</returns>
  370         public static string SpaceToNbsp(string input)
  371         {
  372             string space = " ";
  373             return input.Replace(" ", space);
  374         }
  375 
  376         /// <summary>
  377         /// 把所有換行符號(\n) 和(\r) 轉成HTML 斷行標籤。
  378         /// </summary>
  379         /// <param name="input">輸入字串。</param>
  380         /// <returns>輸出字串。</returns>
  381         public static string NewLineToBreak(string input)
  382         {
  383             Regex regEx = new Regex(@"[\n|\r]+");
  384             return regEx.Replace(input, "<br />");
  385         }
  386 
  387         /// <summary>
  388         /// 判斷傳入的字串是否為空字串。
  389         /// 注意:空白、全形空白、Tab 字元、和換行符號均視為「空」字元。
  390         /// </summary>
  391         /// <param name="input"></param>
  392         /// <returns></returns>
  393         public static bool IsEmpty(string input)
  394         {
  395             string s = StrHelper.RemoveAny(input, new char[] { ' ', ' ', '\t', '\r', '\n', '\0' });
  396             if (String.IsNullOrEmpty(s))
  397                 return true;
  398             return false;
  399         }
  400 
  401         /// <summary>
  402         /// 把內含16 進位值的字串轉成byte。
  403         /// </summary>
  404         /// <param name="input">內含16 進位值的字串,例如:1F、AE。</param>
  405         /// <returns>byte 值。</returns>
  406         public static byte HexStrToByte(string s)
  407         {
  408             return byte.Parse(s, System.Globalization.NumberStyles.HexNumber);
  409         }
  410 
  411         /// <summary>
  412         /// 字串反轉。
  413         /// </summary>
  414         /// <param name="s">輸入字串。</param>
  415         /// <returns>反轉後的字串。</returns>
  416         public static string Reverse(string s)
  417         {
  418             if (String.IsNullOrEmpty(s))
  419                 return "";
  420             char[] charArray = new char[s.Length];
  421             int len = s.Length - 1;
  422             for (int i = 0; i <= len; i++) {
  423                 charArrayIdea = s[len-i];
  424             }
  425             return new string(charArray);
  426         }
  427     }
  428 }

Filed under: .NET General

Attachment(s): CopySourceAsHtml_v2_UncodeFix.zip

評論

# re: 好用的 CopySourceAsHtml,我的中文修正版

2006年10月23日 上午 10:45 by Davis

真沒想到在最不可能處找到這軟體的修正,真是感謝^^

# re: 好用的 CopySourceAsHtml,我的中文修正版

2006年10月23日 上午 10:52 by huanlin

You are welcome :)

but.....最不可能處 ?  ^_^

# re: 好用的 CopySourceAsHtml,我的中文修正版

2006年10月24日 上午 02:43 by hikari

剛試了一下..發現使用VS2005中文版的話..要改一下Source Code.^^

主要是修改選單文字為中文標籤文字.

Connect.cs

<!--

{\rtf1\ansi\ansicpg\lang1024\noproof950\uc1 \deff0{\fonttbl{\f0\fnil\fcharset136\fprq1 &#32048;&#26126;&#39636;;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0??;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;??\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;??\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;??\red192\green192\blue192;}??\fs18  commandBars = (\cf10 CommandBars\cf0 )\cf2 this\cf0 .application.CommandBars;\par ??            editPopup = (\cf10 CommandBarPopup\cf0 )commandBars[\cf13 "MenuBar"\cf0 ].Controls[\cf13 "\uc2\u32232 \'bds\u-28881 \'bf\'e8\uc1(&amp;E)"\cf0 ];\par ??\par ??            copyIndex = FindCopyOnCommandBar(\cf13 "\uc2\u32232 \'bds\u-28881 \'bf\'e8\uc1(&amp;E)"\cf0 ) + 1;}

-->

<div style="font-family: 細明體; font-size: 9pt; color: black; background: white;">

<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;194</span>&nbsp;&nbsp;commandBars = (<span style="color: teal;">CommandBars</span>)<span style="color: blue;">this</span>.application.CommandBars;</p>

<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;195</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; editPopup = (<span style="color: teal;">CommandBarPopup</span>)commandBars[<span style="color: maroon;">"MenuBar"</span>].Controls[<span style="color: maroon;">"&#32232;&#36655;(&amp;E)"</span>];</p>

<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;196</span>&nbsp;</p>

<p style="margin: 0px;"><span style="color: #2b91af;">&nbsp;&nbsp;197</span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; copyIndex = FindCopyOnCommandBar(<span style="color: maroon;">"&#32232;&#36655;(&amp;E)"</span>) + 1;</p>

</div>

# re: 好用的 CopySourceAsHtml,我的中文修正版

2006年10月24日 下午 02:10 by huanlin

To Hikari:

我已經將您提供的程式碼更新到這篇文章了。

感謝!!

# re: 好用的 CopySourceAsHtml,我的中文修正版

2006年11月1日 上午 11:38 by Davis

想來是小弟用錯詞語^^

其實只是想說,小弟在很多地方遍尋不著,卻意外在此地發現。

是真的蠻意外的^^

# re: 好用的 CopySourceAsHtml,我的中文修正版

2006年11月1日 上午 11:45 by huanlin

To Davis:

瞭解,Don't mind. ^_^

該隨筆已禁止評論

from http://huanlin.dyndns.org/cs/blogs/huan-lins_blog/archive/2006/10/20/CopySourceAsHtml-Fix.aspx

2007年8月22日星期三

无法找到编译文件的调试信息,新手问题,望高手解决.

无法找到编译文件的调试信息,新手问题,望高手解决.

楼主BlueSea_zl(蓝海)2006-09-04 12:13:50 在 VC/MFC / 基础类 提问

无法找到"lesson1.exe"的调试信息,或者调试信息不匹配.未使用调试信息生成二进制文件.
要继续调试吗?

这是什么意思?
继续的话能编译运行,但是我想调试的话exe内应该会编入一些调试代码,怎么让它有调试信息呢? 问题点数:100、回复次数:10Top

1 楼xiaoshi0(Rain)回复于 2006-09-04 12:16:44 得分 0

你用的是什么版本的?不同的版本设置的方法不一样Top

2 楼DentistryDoctor(不在无聊中无奈,就在沉默中变态)回复于 2006-09-04 12:18:07 得分 0

你的程序是不是debug版本的,是否包含调试信息?Top

3 楼SoLike(思危)回复于 2006-09-04 12:21:20 得分 0

如果是调试版出现这一问题。看你的设置中是否设置了 “生成调试信息”Top

4 楼BlueSea_zl(蓝海)回复于 2006-09-04 12:31:51 得分 0

你用的是什么版本的?不同的版本设置的方法不一样
是vs2005正式版

你的程序是不是debug版本的,是否包含调试信息?
===========
你的意思是不是说,要自己编写条件编译才有调试信息?
我是新手,不太懂,是不是这个意思?
好像听说软件可以分调试版与正式版,采用条件编译来区分.

如果是调试版出现这一问题。看你的设置中是否设置了 “生成调试信息”
============
你说的是在工具--选项--调试里面的东西吗?Top

5 楼BlueSea_zl(蓝海)回复于 2006-09-04 12:34:49 得分 0

哪家都在用vs2003,说一下vs2003怎么解决也行啊,可能差不多了...Top

6 楼BlueSea_zl(蓝海)回复于 2006-09-04 13:28:47 得分 0

我是选择debug进得编译的啊,结果显示,结果一编译就显示:
无法找到"lesson1.exe"的调试信息,或者调试信息不匹配.未使用调试信息生成二进制文件.
要继续调试吗?Top

7 楼SoLike(思危)回复于 2006-09-04 13:35:36 得分 100

解决方案管理器 -〉选择项目 -〉右键菜单选属性

在弹出窗口中选择 链接器-〉调试-〉生成调试信息 看是否选择为是Top

8 楼jkgl548()回复于 2006-09-04 13:38:29 得分 0

同意Top

9 楼BlueSea_zl(蓝海)回复于 2006-09-04 13:42:08 得分 0

是这样,谢谢
我刚才去查 工具--选项里的那个debug了...
^^Top

10 楼porsche616("︶.︶メ)海洋微風專用( ̄ε ̄メ)回复于 2007-01-10 10:43:39 得分 0

解决方案管理器 -〉选择项目 -〉右键菜单选属性

在弹出窗口中选择 链接器-〉调试-〉生成调试信息 看是否选择为是


——————————————————————
yes!
thx!