local beautifiers = {
	-- std::basic_string
	{
		-- pattern=[[^std::basic_string<.*>$]];
		handler=function(self, id, type_name, sym)
			sym:add_member_map("[raw]", nil);
			local buffer_cap = 16;
			local type_suffix = type_name:sub(-1);
			if type_suffix ~= "*" and type_suffix ~= "&" then
				type_suffix = "";
			end;
			if type_name:match([[std::basic_string<%s*char%s*.*]]) ~= nil then
				sym:set_typename("std::string"..type_suffix);
				buffer_cap = 16;
			elseif type_name:match([[std::basic_string<%s*wchar_t%s*.*]]) ~= nil then
				sym:set_typename("std::wstring"..type_suffix);
				buffer_cap = 8;
			end;
			local capacity_sym = sym:add_member_map("capacity", {"_Mypair","_Myval2","_Myres"});
			capacity_sym.simple_value = true;
			local size_sym = sym:add_member_map("size", {"_Mypair","_Myval2","_Mysize"});
			size_sym.simple_value = true;
			local value;
			if capacity_sym.value>=buffer_cap then
				value = sym:add_member_map("ptr", {"_Mypair","_Myval2","_Bx","_Ptr"});
			else
				value = sym:add_member_map("ptr", {"_Mypair","_Myval2","_Bx","_Buf"});
			end;
			-- make ptr as the string's value member
			sym:set_display_mem_value("ptr");
			-- override value with custom format
			sym:set_display_value(([[{size=%d,%s}]]):format(size_sym.value, value.value));
			return true;
		end;
	};
};

libcxx_beautifier = edx.get_debugger_beautifier("libc++");

function libcxx_beautifier.on_beautify_symbol(self, id, type_name, sym)
	local handler = self.__beautifiers[id];
	if not handler then
		return false;
	end;
	return handler(id, type_name, sym);
end;

local libcxx_beautifier_map = {};

for i, obj in ipairs(beautifiers) do
	if obj.pattern then
		local idx = libcxx_beautifier:add_beautify_pattern(obj.pattern);
		libcxx_beautifier_map[idx] = (function(the_obj)
				return function(...)
					return the_obj:handler(...);
				end;
		end)(obj);
	end;
end;

libcxx_beautifier.__beautifiers = libcxx_beautifier_map;

print( "load libc++ beautifier ok!");
