Index: branches/egtra/ab5.0/jenga/projects/jenga/stdafx.h
===================================================================
--- branches/egtra/ab5.0/jenga/projects/jenga/stdafx.h	(revision 818)
+++ branches/egtra/ab5.0/jenga/projects/jenga/stdafx.h	(revision 826)
@@ -1,4 +1,5 @@
 #pragma once
 
+#include <algorithm>
 #include <map>
 #include <string>
@@ -21,6 +22,7 @@
 #include <assert.h>
 
-//boost libraries
 #include <boost/foreach.hpp>
+#include <boost/implicit_cast.hpp>
+#include <boost/range/algorithm.hpp>
 #include <boost/serialization/serialization.hpp>
 #include <boost/serialization/nvp.hpp>
Index: branches/egtra/ab5.0/jenga/src/common/String.cpp
===================================================================
--- branches/egtra/ab5.0/jenga/src/common/String.cpp	(revision 818)
+++ branches/egtra/ab5.0/jenga/src/common/String.cpp	(revision 826)
@@ -1,84 +1,100 @@
 #include "stdafx.h"
-#include <algorithm>
+#include <boost/numeric/conversion/cast.hpp>
+#include <boost/algorithm/string/replace.hpp>
 
-bool Jenga::Common::IsExistString( const Jenga::Common::Strings &strings, const std::string &findStr )
+using boost::numeric_cast;
+using boost::implicit_cast;
+
+bool Jenga::Common::IsExistString(const Jenga::Common::Strings &strings, const std::string &findStr)
 {
-	return std::find( strings.begin(), strings.end(), findStr ) != strings.end();
+	return boost::find(strings, findStr) != strings.end();
 }
 
-std::string& Jenga::Common::StringReplace( std::string& str, const std::string &sb, const std::string &sa )
+std::string& Jenga::Common::StringReplace(std::string& str, const std::string &sb, const std::string &sa)
 {
-	std::string::size_type n, nb = 0;
-	
-	while ((n = str.find(sb,nb)) != std::string::npos)
-	{
-		str.replace(n,sb.size(),sa);
-		nb = n + sa.size();
-	}
-	
+	boost::algorithm::replace_all(str, sb, sa);
 	return str;
 }
 
-std::string Jenga::Common::ToString( int n )
+std::string Jenga::Common::ToString(int n)
 {
-	char temp[255];
-	wsprintf( temp, "%d", n );
-	return temp;
+	// VC++ 2010だとこのキャストが必要。
+	return std::to_string(implicit_cast<long long>(n));
 }
 
 std::string Jenga::Common::ToString( const std::wstring &wstr )
 {
-	int needSize = 	WideCharToMultiByte(
-		CP_THREAD_ACP,
+	if (wstr.empty())
+	{
+		return std::string();
+	}
+	int srcSize = numeric_cast<int>(wstr.size());
+	int needSize = WideCharToMultiByte(
+		CP_ACP,
 		0,
-		wstr.data(), static_cast<int>(wstr.size()),
-		NULL, NULL,
-		NULL, NULL );
+		wstr.data(), srcSize,
+		nullptr, 0,
+		nullptr, nullptr);
+	if (needSize <= 0)
+	{
+		throw std::runtime_error("WideCharToMultiByte error");
+	}
 
-	char *pstr = (char *)calloc( needSize, 1 );
-	WideCharToMultiByte(
-		CP_THREAD_ACP,
+	std::string ret(needSize, '\0');
+	int res = WideCharToMultiByte(
+		CP_ACP,
 		0,
-		wstr.data(), static_cast<int>(wstr.size()),
-		pstr, needSize,
-		NULL, NULL );
+		wstr.data(), srcSize,
+		&ret[0], needSize,
+		nullptr, nullptr);
+	if (res <= 0)
+	{
+		throw std::runtime_error("WideCharToMultiByte error");
+	}
 
-	std::string result(pstr, needSize);
-
-	free( pstr );
-
-	return result;
+	return ret;
 }
 
-std::wstring Jenga::Common::ToWString( const std::string &str )
+std::wstring Jenga::Common::ToWString(const std::string &str)
 {
-	int size = MultiByteToWideChar(
+	if (str.empty())
+	{
+		return std::wstring();
+	}
+	int srcSize = numeric_cast<int>(str.size());
+	int needSize = MultiByteToWideChar(
 		CP_ACP,
 		0,
-		str.data(), static_cast<int>(str.size()),
-		NULL, 0 );
+		str.data(), srcSize,
+		nullptr, 0);
+	if (needSize <= 0)
+	{
+		throw std::runtime_error("WideCharToMultiByte error");
+	}
 
-	LPWSTR pwstr = (LPWSTR)calloc( size, sizeof (wchar_t) );
-
-	MultiByteToWideChar(
+	std::wstring ret(needSize, L'\0');
+	int res = MultiByteToWideChar(
 		CP_ACP,
 		0,
-		str.data(), static_cast<int>(str.size()),
-		pwstr, size );
+		str.data(), srcSize,
+		&ret[0], needSize);
+	if (res <= 0)
+	{
+		throw std::runtime_error("WideCharToMultiByte error");
+	}
 
-	std::wstring wstr( pwstr, size );
-
-	free( pwstr );
-
-	return wstr;
+	return ret;
 }
 
 bool Jenga::Common::IsIdentifierTopChar( char c )
 {
-	return ( isalpha( c ) || c == '_' );
+	return ('A' <= c && c <= 'Z')
+		|| ('a' <= c && c <= 'z')
+		|| c == '_' ;
 }
 
 bool Jenga::Common::IsIdentifierChar( char c )
 {
-	return ( IsIdentifierTopChar( c ) || isdigit( c ) );
+	return IsIdentifierTopChar(c)
+		|| ('0' <= c && c <= '9');
 }
