473,394 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Paragraph Packing

Page <URL:http://www.merlyn.demon.co.uk/js-quick.htm> now contains code
to pack text into multiple paragraphs of given right margin (the nominal
range is from 1 to nearly Infinity).
function Pak(F) { var S = F.Code.value, L = +F.Len.value, J, Re
S = S.replace(/(\r?\n){2,}/g, "\u0000").replace(/(\r?\n)/g, " ")
S = S.replace(/\s+/g, " ").split("\u0000")
if (L<1) L = F.Len.value = 1
Re = new RegExp("(.{1," + L + "}) ", "g")
J = S.length ; while (J--)
S[J] = (S[J].replace(/^\s+/, "")+" ").replace(Re, "$1\n")
F.Code.value = S.join("\n") }
F.Code is the I/O textarea; Code.L gives the margin.

The input paragraph separator is an empty line or lines.

It works in my IE4 ; any comment, particularly in respect of recognising
line-ends in non-Windows systems ?

Also - is anything wrong with using \u0000 as a marker?
The feature can be used to normalise badly-posted plain text, for more
comfortable reading.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Dec 11 '05 #1
2 1683
Dr John Stockton wrote:
[...]
It works in my IE4 ; any comment, particularly in respect of recognising
line-ends in non-Windows systems ?


Seems to work fine in Safari 1.0.3, it does not recognise new lines in
IE 5.2 (Mac). I'll mess around with and see if I can find the
appropriate character - maybe \u0000 is the issue.
[...]
--
Rob
Dec 13 '05 #2
JRS: In article <439e9bbb$0$3672$5a62ac22@per-qv1-newsreader-
01.iinet.net.au>, dated Tue, 13 Dec 2005 20:00:27 local, seen in
news:comp.lang.javascript, RobG <rg***@iinet.net.auau> posted :
Dr John Stockton wrote:
[...]
It works in my IE4 ; any comment, particularly in respect of recognising
line-ends in non-Windows systems ?


Seems to work fine in Safari 1.0.3, it does not recognise new lines in
IE 5.2 (Mac). I'll mess around with and see if I can find the
appropriate character - maybe \u0000 is the issue.


Could be; for test purposes one can use the uncontentious but rare #
instead; literally or as \u0023 (?).

But I'd look closely at the two (\r?\n) ... It may be necessary to do
them in two stages each, first for \r\n and second for \r|\n.
Thanks for looking.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Dec 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: nobull | last post by:
Google won't let me post this as a follow-up but lynch@agere.com (lynto) wrote in message news:<503469eb.0407271148.7ee4b0ca@posting.google.com>... > Does anyone have an algorithm for packing...
2
by: gbb0330 | last post by:
Hi all I need some advice. the daily packing number will be used to match a box with its label. the guys in the warehouse will get a list of items to pack. they will find the item - put it...
1
by: gbb0330 | last post by:
hi guys -the code (all capital letters) generates daily packing number, it is in the on click event of a command button that moves to the next record. dpkn is unbound control - i use it to...
2
by: FMorales | last post by:
Hello all, quick hopefully easy question. Here goes. I've started on the Art Of Assembly tutorial(s) (http://webster.cs.ucr.edu/Page_asm/0_ArtOfAsm.html) and got to the sample projects and kinda...
18
by: Edward Diener | last post by:
Is the packing alignment of __nogc classes stored as part of the assembly ? I think it must as the compiler, when referencing the assembly, could not know how the original data is packed otherwise....
1
by: Gajendra | last post by:
How does the byte packing and the byte alignment work in VC++ compiler? What is the effect of #pragma pack(n) on the alignment and byte packing for example while using the structur struc double...
9
by: fraz | last post by:
Does anyone have code to solve a 3-d bin packing problem in php? I am trying to solve the issue of packing various sized rectangular shaped objects into boxes of three different sizes so as to use...
1
by: QbProg | last post by:
Hello, what I'm saying here is about VS 2005 WITHOUT service pack. I have two DLL projects, with EXACTLY the same project preferences and settings. Both have alignment set to "default", it...
3
by: gentsquash | last post by:
I'm trying to display a paragraph that has a centered phrase, such as this one, in the middle of the paragraph. An example is the section "End of semester project" on my course-page ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.