Exemplo n.º 1
0
void double_to_string(double blah, pfc::string_base & p_out, int points = 10, bool ms = true)
{
	int decimal, sign;
	pfc::array_t<char> buffer;
	buffer.set_size(_CVTBUFSIZE);
	buffer.fill_null();
	_fcvt_s(buffer.get_ptr(), buffer.get_size(), blah*(ms ? 1000.0 : 1.0), points, &decimal, &sign);
	const char * ptr = buffer.get_ptr();
	if (decimal <= 0)
	{
		p_out.add_string("0.",2);
		while (decimal) 
		{
			p_out.add_byte('0');
			decimal ++;
		}
		p_out.add_string(ptr, pfc_infinite);
	}
	else
	{
		p_out.add_string(ptr, decimal);
		p_out.add_string(".",1);
		ptr += decimal;
		p_out.add_string(ptr,pfc_infinite);
	}
}
Exemplo n.º 2
0
	void insert(const char * src,unsigned idx,pfc::string_base & out)
	{
		out.reset();
		out.add_string(src,idx);
		out.add_string("&");
		out.add_string(src+idx);
		used.add_char(uCharLower(src[idx]));
	}
Exemplo n.º 3
0
bool archive_impl::get_display_path(const char * path,pfc::string_base & out)
{
	pfc::string8 archive,file;
	if (g_parse_unpack_path(path,archive,file))
	{
		g_get_display_path(archive,out);
		out.add_string("|");
		out.add_string(file);
		return true;
	}
	else return false;
}
Exemplo n.º 4
0
	void mainpath_from_guid(const GUID & p_guid, const GUID & p_subguid, pfc::string_base & p_out, bool b_short)
	{
		p_out.reset();
		service_enum_t<mainmenu_commands> e;
		service_ptr_t<mainmenu_commands> ptr;

		unsigned p_service_item_index;
		while (e.next(ptr))
		{
			service_ptr_t<mainmenu_commands_v2> ptr_v2;
			ptr->service_query_t(ptr_v2);
			unsigned p_service_item_count = ptr->get_command_count();
			for (p_service_item_index = 0; p_service_item_index < p_service_item_count; p_service_item_index++)
			{
				if (p_guid == ptr->get_command(p_service_item_index))
				{
					pfc::string8 name;
					ptr->get_name(p_service_item_index, name);
					if (p_subguid != pfc::guid_null && ptr_v2.is_valid() && ptr_v2->is_command_dynamic(p_service_item_index))
					{
						pfc::string8 name_sub;
						mainmenu_node::ptr ptr_node = ptr_v2->dynamic_instantiate(p_service_item_index);
						mainmenunode_subguid_to_path(ptr_node, p_subguid, name_sub, true);
						name << "/" << name_sub;
					}
					if (!b_short)
					{
						pfc::list_t<pfc::string8> levels;
						GUID parent = ptr->get_parent();
						while (parent != pfc::guid_null)
						{
							pfc::string8 parentname;
							if (maingroupname_from_guid(GUID(parent), parentname, parent))
								levels.insert_item(parentname, 0);
						}
						unsigned i, count = levels.get_count();
						for (i = 0; i<count; i++)
						{
							p_out.add_string(levels[i]);
							p_out.add_byte('/');

						}
					}
					p_out.add_string(name);
				}

			}
		}
	}
Exemplo n.º 5
0
	virtual bool
	context_get_display(
		unsigned int			index,
		metadb_handle_list_cref	tracks,
		pfc::string_base&		out,
		unsigned int&			/*displayflags*/,
		const GUID&				/*caller*/
	)
	{
		switch(index)
		{
			case Items::ReplaceWithBestVersion:
			{
				out = "Replace with best version of track";

				if(tracks.get_count() > 1)
				{
					out.add_string("s");
				}

				return true;
			}

			default:
			{
				// Nothing wants to customise the display of the item; let the regular name be displayed.
				get_item_name(index, out);
				return true;
			}
		}
	}
Exemplo n.º 6
0
static void fix_ampersand(const char * src,pfc::string_base & out)
{
	unsigned ptr = 0;
	while(src[ptr])
	{
		if (src[ptr]=='&')
		{
			out.add_string("&&");
			ptr++;
			while(src[ptr]=='&')
			{
				out.add_string("&&");
				ptr++;
			}
		}
		else out.add_byte(src[ptr++]);
	}
}
Exemplo n.º 7
0
void ui_extension::menu_hook_impl::fix_ampersand(const char * src,pfc::string_base & out)
{
	unsigned ptr = 0;
	while(src[ptr])
	{
		if (src[ptr]=='&')
		{
			out.add_string("&&");
			ptr++;
			while(src[ptr]=='&')
			{
				out.add_string("&&");
				ptr++;
			}
		}
		else out.add_byte(src[ptr++]);
	}
}
Exemplo n.º 8
0
void stream_reader::read_string_raw(pfc::string_base & p_out,abort_callback & p_abort) {
	enum {delta = 256};
	char buffer[delta];
	p_out.reset();
	for(;;) {
		t_size delta_done;
		delta_done = read(buffer,delta,p_abort);
		p_out.add_string(buffer,delta_done);
		if (delta_done < delta) break;
	}
}
Exemplo n.º 9
0
	bool __contextpath_from_guid_recur(contextmenu_item_node * p_node, const GUID & p_subcommand, pfc::string_base & p_out, bool b_short, bool b_root)
	{
		if (p_node)
		{
			if (p_node->get_type() == contextmenu_item_node::TYPE_POPUP)
			{
				pfc::string8 subname, temp = p_out;
				unsigned dummy;
				p_node->get_display_data(subname, dummy, metadb_handle_list(), contextmenu_item::caller_keyboard_shortcut_list);
				if (temp.get_length() && temp.get_ptr()[temp.get_length() - 1] != '/')
					temp.add_byte('/');
				temp << subname;
				unsigned child, child_count = p_node->get_children_count();
				for (child = 0; child<child_count; child++)
				{
					contextmenu_item_node * p_child = p_node->get_child(child);
					if (__contextpath_from_guid_recur(p_child, p_subcommand, temp, b_short, false))
					{
						p_out = temp;
						return true;
					}
				}
			}
			else if (p_node->get_type() == contextmenu_item_node::TYPE_COMMAND && !b_root)
			{
				if (p_node->get_guid() == p_subcommand)
				{
					pfc::string8 subname;
					unsigned dummy;
					p_node->get_display_data(subname, dummy, metadb_handle_list(), contextmenu_item::caller_keyboard_shortcut_list);
					if (!b_short)
						p_out.add_byte('/');
					else
						p_out.reset();
					p_out.add_string(subname);
					return true;
				}
			}
		}
		return false;
	}
Exemplo n.º 10
0
	void contextpath_from_guid(const GUID & p_guid, const GUID & p_subcommand, pfc::string_base & p_out, bool b_short)
	{
		p_out.reset();
		service_enum_t<contextmenu_item> e;
		service_ptr_t<contextmenu_item> ptr;

		unsigned p_service_item_index;
		while (e.next(ptr))
		{
			unsigned p_service_item_count = ptr->get_num_items();
			for (p_service_item_index = 0; p_service_item_index < p_service_item_count; p_service_item_index++)
			{
				if (p_guid == ptr->get_item_guid(p_service_item_index))
				{
					pfc::string8 name;
					ptr->get_item_name(p_service_item_index, name);
					if (!b_short)
					{
						ptr->get_item_default_path(p_service_item_index, p_out);
						if (p_out.get_length() && p_out[p_out.get_length() - 1] != '/')
							p_out.add_byte('/');
					}
					p_out.add_string(name);

					if (p_subcommand != pfc::guid_null)
					{
						pfc::ptrholder_t<contextmenu_item_node_root> p_node(ptr->instantiate_item(p_service_item_index, metadb_handle_list(), contextmenu_item::caller_keyboard_shortcut_list));

						if (p_node.is_valid())
							if (__contextpath_from_guid_recur(p_node.get_ptr(), p_subcommand, p_out, b_short, true))
								return;
					}
				}

			}
		}
	}
Exemplo n.º 11
0
	virtual bool
	context_get_display(
		unsigned int			index,
		metadb_handle_list_cref	tracks,
		pfc::string_base&		out,
		unsigned int&			displayflags,
		const GUID&				/*caller*/
	)
	{
		switch(index)
		{
			case Items::GetArtistTopTracks:
			{
				const auto& mainArtist = getMainArtist(tracks);

				const t_size stringLength = mainArtist.length();

				if(stringLength > 0)
				{
					// We have found a main artist; set the display of the item to be of the form:
					// "Artist's top tracks".
					out = mainArtist.c_str();

					// Grammar alert! Artists ending with "s" get just a "'" rather than "'s".
					if(out[stringLength - 1] == 's')
					{
						out.add_string("' top tracks");
					}
					else
					{
						out.add_string("'s top tracks");
					}
				}
				else
				{
					// Failed to find a main artist; return the normal, non-custom name for the item.
					get_item_name(index, out);
				}

				return true;
			}

			case Items::GetSimilarTracks:
			{
				if(tracks.get_count() == 0)
				{
					displayflags = FLAG_DISABLED_GRAYED;
					get_item_name(index, out);
				}
				else
				{
					out = "Get tracks similar to ";
					out.add_string(getTitle(tracks.get_item(0)).c_str());
				}

				return true;
			}

			default:
			{
				// Nothing wants to customise the display of the item; let the regular name be displayed.
				get_item_name(index, out);
				return true;
			}
		}
	}
Exemplo n.º 12
0
	void read_v2(const service_ptr_t<file> & p_file,abort_callback & p_abort,pfc::string_base & p_out,bool & is_utf8, bool forceUTF8) {
		p_out.reset();
		p_file->reopen( p_abort );
		
		pfc::array_t<char> mem;
		t_filesize size64;
		size64 = p_file->get_size(p_abort);
		if (size64 == filesize_invalid)//typically HTTP
		{
			pfc::string8 ansitemp;
			t_size done;
			enum { delta = 1024 * 64, max = 1024 * 512 };

			if ( forceUTF8 ) {
				is_utf8 = true;
			} else {
				is_utf8 = false;
				char temp[3];
				done = p_file->read(temp, 3, p_abort);
				if (done != 3)
				{
					if (done > 0) p_out = pfc::stringcvt::string_utf8_from_ansi(temp, done);
					return;
				}
				if (!memcmp(utf8_header, temp, 3)) is_utf8 = true;
				else ansitemp.add_string(temp, 3);
			}

			mem.set_size(delta);
			
			for(;;)
			{
				done = p_file->read(mem.get_ptr(),delta,p_abort);
				if (done > 0)
				{
					if (is_utf8) p_out.add_string(mem.get_ptr(),done);
					else ansitemp.add_string(mem.get_ptr(),done);
				}
				if (done < delta) break;
			}

			if (!is_utf8)
			{
				p_out = pfc::stringcvt::string_utf8_from_ansi(ansitemp);
			}

			return;
		}
		else
		{
			if (size64>1024*1024*128) throw exception_io_data();//hard limit
			t_size size = pfc::downcast_guarded<t_size>(size64);
			mem.set_size(size+1);
			char * asdf = mem.get_ptr();
			p_file->read_object(asdf,size,p_abort);
			asdf[size]=0;
			if ( forceUTF8 ) {
				is_utf8 = true;
				p_out = asdf;
			} else if (size>3 && !memcmp(utf8_header,asdf,3)) {
				is_utf8 = true; 
				p_out.add_string(asdf+3); 
			} else {
				is_utf8 = false;
				p_out = pfc::stringcvt::string_utf8_from_ansi(asdf);
			}
			return;
		}
	}