Herbert's xhfill package "is a package for extended hfillrules." It provides
\xhrulefill: Modified dimensions for \hrulefill
\xrfill: Coloured horizontal rules
\xdotfill: Dotted \hrulefill
\xhrectanglefill: Rectangular fills
and in the documentation also defines:
\newcommand{\xfill}[2][1ex]{{%
\dimen0=#2\advance\dimen0 by #1
\leaders\hrule height \dimen0 depth -#1\hfill%
}}
\newcommand{\xfilll}[2][1ex]{%
\dimen0=#2\advance\dimen0 by #1%
\leaders\hrule height \dimen0 depth -#1\hfill%
}
The following, taken partially from the documentation, is an example of the rules generated:

\documentclass{article}
\usepackage{listings}% http://ctan.org/pkg/listings
%\usepackage{xcolor}% http://ctan.org/pkg/xcolor | Loaded by listings
\usepackage{xhfill}% http://ctan.org/pkg/xhfill
\setlength{\parindent}{0pt}% Just for this example
\newcommand{\xfill}[2][1ex]{{%
\dimen0=#2\advance\dimen0 by #1
\leaders\hrule height \dimen0 depth -#1\hfill%
}}
\newcommand{\xfilll}[2][1ex]{%
\dimen0=#2\advance\dimen0 by #1%
\leaders\hrule height \dimen0 depth -#1\hfill%
}
\begin{document}
blah\xfilll{1pt}blub
\begin{lstlisting}
blah\xfilll{1pt}blub
\end{lstlisting}
blah\xfilll{1pt}blub
\begin{lstlisting}
blah\xfilll{1pt}blub
\end{lstlisting}
blah\xfilll[0pt]{4pt}blub
\begin{lstlisting}
blah\xfilll[0pt]{4pt}blub
\end{lstlisting}
blah\xfilll[-12pt]{12pt}blub
\begin{lstlisting}
blah\xfilll[-12pt]{12pt}blub
\end{lstlisting}
blah\xrfill{1pt}[blue]blub blah\xrfill{2pt}[cyan]blub
\begin{lstlisting}
blah\xrfill{1pt}[blue]blub blah\xrfill{2pt}[cyan]blub
\end{lstlisting}
laber\xrfill[0pt]{4pt}[green]blub blub
\begin{lstlisting}
laber\xrfill[0pt]{4pt}[green]blub blub
\end{lstlisting}
blah\xrfill[-1ex]{1pt}[red]blub
\begin{lstlisting}
blah\xrfill[-1ex]{1pt}[red]blub
\end{lstlisting}
blah \xhrulefill{cyan}{1cm} blub
\begin{lstlisting}
blah \xhrulefill{cyan}{1cm} blub
\end{lstlisting}
blah \xhrectanglefill{0.5cm}{1pt} blubber
\begin{lstlisting}
blah \xhrectanglefill{0.5cm}{1pt} blubber
\end{lstlisting}
blah\xdotfill{1pt}[blue]blah\xdotfill{2pt}[red]blub
\begin{lstlisting}
blah\xdotfill{1pt}[blue]blah\xdotfill{2pt}[red]blub
\end{lstlisting}
\end{document}
Although these rules are all constructed as leaders, and therefore span the entire width in a "fill" manner, they can also be made to be of a specific length.
\noindent. – Yiannis Lazarides May 1 '11 at 22:14