| 
									
										
										
										
											2009-01-26 03:21:28 -05:00
										 |  |  | ! Copyright (C) 2009 Slava Pestov. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2009-04-30 21:03:52 -04:00
										 |  |  | USING: kernel sequences fry math.order splitting ;
 | 
					
						
							| 
									
										
										
										
											2009-01-26 03:21:28 -05:00
										 |  |  | IN: strings.tables | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <PRIVATE
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-30 21:03:52 -04:00
										 |  |  | : map-last ( seq quot -- seq )
 | 
					
						
							|  |  |  |     [ dup length <reversed> ] dip '[ 0 = @ ] 2map ; inline
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : max-length ( seq -- n )
 | 
					
						
							|  |  |  |     [ length ] [ max ] map-reduce ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : format-row ( seq ? -- seq )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         dup max-length
 | 
					
						
							|  |  |  |         '[ _ "" pad-tail ] map
 | 
					
						
							|  |  |  |     ] unless ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-26 03:21:28 -05:00
										 |  |  | : format-column ( seq ? -- seq )
 | 
					
						
							|  |  |  |     [ | 
					
						
							| 
									
										
										
										
											2009-04-30 21:03:52 -04:00
										 |  |  |         dup max-length
 | 
					
						
							| 
									
										
										
										
											2009-01-30 04:37:01 -05:00
										 |  |  |         '[ _ CHAR: \s pad-tail ] map
 | 
					
						
							| 
									
										
										
										
											2009-01-26 03:21:28 -05:00
										 |  |  |     ] unless ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PRIVATE>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : format-table ( table -- seq )
 | 
					
						
							| 
									
										
										
										
											2009-04-30 21:03:52 -04:00
										 |  |  |     [ [ [ string-lines ] map ] dip format-row flip ] map-last concat
 | 
					
						
							|  |  |  |     flip [ format-column ] map-last flip [ " " join ] map ;
 |