Router improvements

- Make dashes-to-underscores URI segment replacement configurable via ['translate_uri_dashes'].
- Make _set_routing() protected and move the call to the class constructor.
- Remove redudant calls to set_class() and set_method().
- Clean-up/optimize the routes loading procedure.

(fixes issue #2503)
diff --git a/system/core/Router.php b/system/core/Router.php
index c86ab9c..cc3916f 100644
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -82,6 +82,18 @@
 	public $default_controller;
 
 	/**
+	 * Translate URI dashes
+	 *
+	 * Determines whether dashes in controller & method segments
+	 * should be automatically replaced by underscores.
+	 *
+	 * @var	bool
+	 */
+	public $translate_uri_dashes = FALSE;
+
+	// --------------------------------------------------------------------
+
+	/**
 	 * Class constructor
 	 *
 	 * Runs the route mapping function.
@@ -92,6 +104,7 @@
 	{
 		$this->config =& load_class('Config', 'core');
 		$this->uri =& load_class('URI', 'core');
+		$this->_set_routing();
 		log_message('debug', 'Router Class Initialized');
 	}
 
@@ -105,7 +118,7 @@
 	 *
 	 * @return	void
 	 */
-	public function _set_routing()
+	protected function _set_routing()
 	{
 		// Are query strings enabled in the config file? Normally CI doesn't utilize query strings
 		// since URI segments are more search-engine friendly, but they can optionally be used.
@@ -143,12 +156,14 @@
 			include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
 		}
 
-		$this->routes = (empty($route) OR ! is_array($route)) ? array() : $route;
-		unset($route);
-
-		// Set the default controller so we can display it in the event
-		// the URI doesn't correlated to a valid controller.
-		$this->default_controller = empty($this->routes['default_controller']) ? FALSE : $this->routes['default_controller'];
+		// Validate & get reserved routes
+		if (isset($route) && is_array($route))
+		{
+			isset($route['default_controller']) && $this->default_controller = $route['default_controller'];
+			isset($route['translate_uri_dashes']) && $this->translate_uri_dashes = $route['translate_uri_dashes'];
+			unset($route['default_controller'], $route['translate_uri_dashes']);
+			$this->routes = $route;
+		}
 
 		// Were there any query string segments? If so, we'll validate them and bail out since we're done.
 		if (count($segments) > 0)
@@ -191,8 +206,6 @@
 			$method = 'index';
 		}
 
-		$this->set_class($class);
-		$this->set_method($method);
 		$this->_set_request(array($class, $method));
 
 		// re-index the routed segments array so it starts with 1 rather than 0
@@ -221,8 +234,16 @@
 			return $this->_set_default_controller();
 		}
 
-		$this->set_class($segments[0]);
+		if ($this->translate_uri_dashes === TRUE)
+		{
+			$segments[0] = str_replace('-', '_', $segments[0]);
+			if (isset($segments[1]))
+			{
+				$segments[1] = str_replace('-', '_', $segments[1]);
+			}
+		}
 
+		$this->set_class($segments[0]);
 		isset($segments[1]) OR $segments[1] = 'index';
 		$this->set_method($segments[1]);
 
@@ -249,13 +270,12 @@
 			return $segments;
 		}
 
-		$temp = str_replace('-', '_', $segments[0]);
+		$test = ($this->translate_uri_dashes === TRUE)
+			? str_replace('-', '_', $segments[0]) : $segments[0];
 
 		// Does the requested controller exist in the root folder?
-		if (file_exists(APPPATH.'controllers/'.$temp.'.php'))
+		if (file_exists(APPPATH.'controllers/'.$test.'.php'))
 		{
-			$segments[0] = $temp;
-			empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]);
 			return $segments;
 		}
 
@@ -266,11 +286,11 @@
 			$this->set_directory(array_shift($segments));
 			if (count($segments) > 0)
 			{
-				$segments[0] = str_replace('-', '_', $segments[0]);
-				empty($segments[1]) OR $segments[1] = str_replace('-', '_', $segments[1]);
+				$test = ($this->translate_uri_dashes === TRUE)
+					? str_replace('-', '_', $segments[0]) : $segments[0];
 
-				// Does the requested controller exist in the sub-folder?
-				if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$segments[0].'.php'))
+				// Does the requested controller exist in the sub-directory?
+				if ( ! file_exists(APPPATH.'controllers/'.$this->directory.$test.'.php'))
 				{
 					if ( ! empty($this->routes['404_override']))
 					{