I have an NSLayoutManager, two NSTextContainers, and an NSTextStorage object.
I add strings one by one to the textStorage object until the first textContainer is full, then I use the amount of text added to that textContainer draw a page in my book app.
99% of the time the isAtEnd flag in didCompleteLayoutForTextContainer will tell me when the first text container got full.
However, in a rare case, if I add a string to the textStorage it will actually remove text from the first text container!
For example, when the first text container has this string in it (and is almost full):
\n\n\n\n\n\nMexico \n\nBook Covers from Germany \n\n \n\n \n\n Book Covers from Germany Special Edition \n\nBook Covers from Denmark Sweden \n\nBook Covers from Japan \n\nBook Covers From Finland \n\nBook Covers From Greece
if I add this string to the textStorage:
Spain \n\nBook Covers From Iceland \n\nBook Covers From Netherlands \n\nBook Covers from Norway
the layoutManager will move the word "Greece" from the first textContainer and move it to the second textContainer.
I would have rather had the layoutManager tell me that the first textContainer was full before I attempted to add a new string and have it do this unexpected behavior.
Can anyone tell me why this is happening? or tell me how I can tell when this will happen again so that I can figure out when the first textContainer is really full?
Thanks!
May be create subclass to NSTypesetter and override the method layoutParagraphAtPoint() . This method returns next character that will be at the beginning of nexy paragraph, or may be at end of textContainer - I am not sure.
Related
I have a text from which I want to extract the first two paragraphs. The text consists of several paragraphs seperated by empty lines. The paragraphs themselves can contain line breaks. What I want to extract is everything from the beginning of the text until the second empty line. This is the original text:
Today I meet my friends in Kyiv to celebrate my new permanent residency status in Ukraine.
Then I went to a nice restaurant with them.
Buy me a Beer: https://www.buymeacoffee.com/johnnyfd
Support the GoFundMe: http://gofundme.com/f/send-money-dire...
Follow Me:
The text I want to have is:
Today I meet my friends in Kyiv to celebrate my new permanent residency status in Ukraine.
Then I went to a nice restaurant with them.
Buy me a Beer: https://www.buymeacoffee.com/johnnyfd
I tried to create a regular expression doing the job and I though the following seemed to be a possible solution:
(.*|\n)*(?:[[:blank:]]*\n){2,}(.*|\n)*(?:[[:blank:]]*\n){2,}
When I use it in R in stri_extract_all_regex, I receive the following error:
Error in stri_extract_all_regex(video_desc_orig, "(.*|\n)*?(?:[[:blank:]]*\n){2,}(.*?|\n)*(?:[[:blank:]]*\n){2,}") :
Regular expression backtrack stack overflow. (U_REGEX_STACK_OVERFLOW)
It's the first time for me using Regex and I really don't know how to interpret this error. Any help appreciated ;)
You have nested quantifiers like (.*|\n)* which creates a lot of paths to explore. This pattern for example first matches all text, and then starts to backtrack to fit in the next parts of the pattern.
Including the last 2 newlines, making sure that the lines contain at least a single non whitespace character:
\A[^\S\n]*\S.*(?:\n[^\S\n]*\S.*)*\n{2,}[^\S\n]*\S.*(?:\n[^\S\n]*\S.*)*
Explanation
\A Start of string
[^\S\n]*\S.* Match a whole line with at least a single non whitespace char
(?:\n[^\S\n]*\S.*)* Optionally repeat all following lines that contain at least a single non whitespace chars
\n{2,} Match 2 or more newlines
[^\S\n]*\S.*(?:\n[^\S\n]*\S.*)* Same as the previous pattern to match the lines for the second paragraph
See a regex demo and a R demo.
Example
library(stringi)
string <- 'Today I meet my friends in Kyiv to celebrate my new permanent residency status in Ukraine.
Then I went to a nice restaurant with them.
Buy me a Beer: https://www.buymeacoffee.com/johnnyfd
Support the GoFundMe: http://gofundme.com/f/send-money-dire...
Follow Me: '
stri_extract_all_regex(
string,
'\\A[^\\S\\n]*\\S.*(?:\\n[^\\S\\n]*\\S.*)*\\n{2,}[^\\S\\n]*\\S.*(?:\\n[^\\S\\n]*\\S.*)*'
)
Output
[[1]]
[1] "Today I meet my friends in Kyiv to celebrate my new permanent residency status in Ukraine.\nThen I went to a nice restaurant with them.\n\nBuy me a Beer: https://www.buymeacoffee.com/johnnyfd"
In R you need to do double slashes \\.
string <- 'Today I meet my friends in Kyiv to celebrate my new permanent residency status in Ukraine.
Then I went to a nice restaurant with them.
Buy me a Beer: https://www.buymeacoffee.com/johnnyfd
Support the GoFundMe: http://gofundme.com/f/send-money-dire...
Follow Me: '
library(stringr)
string |>
str_extract('(.*|\\n)*(?:[[:blank:]]*\\n){2,}(.*|\\n)*(?:[[:blank:]]*\\n){2,}') |>
cat()
# Output
Today I meet my friends in Kyiv to celebrate my new permanent residency status in Ukraine.
Then I went to a nice restaurant with them.
Buy me a Beer: https://www.buymeacoffee.com/johnnyfd
I have a .txt file that contains multiple newspaper articles. Each article has a headline, the author name etc. I want to read the whole .txt file in R and remove every line + the next 5 lines that starts with certain words. I think gsub + reg expression might be the solution, but I do not know how to define it like the way so that not only the line containing these words is deleted, but also the next 5 lines.
Edit:
The txt. file consists of 200 Washington Post articles. Each article ends with:
lydia.depillis#washpost.com
LOAD-DATE: July 14, 2013
LANGUAGE: ENGLISH
PUBLICATION-TYPE: Web Publication
Copyright 2013 Washingtonpost.Newsweek Interactive Company, LLC d/b/a Washington
Post Digital
All Rights Reserved
4 of 200 DOCUMENTS
Washington Post Blogs
In the Loop
June 28, 2013 Friday 3:08 PM EST
Whenever an e-mail address appears, I want to delete everything until the line where a date appears so that we have a smooth transition to the next article. I want to use a sentiment analysis and thus don't need these lines.
Hello every one here i am Generating a BarCode using Font Free 3 of 9 like this in a .rdlc Report Page.
<Textbox Name="ID">
<rd:DefaultName>ID</rd:DefaultName>
<Top>1.1in</Top>
<Width>1.15 in</Width>
<Style>
<FontFamily>Free 3 of 9</FontFamily>
<FontSize>28pt</FontSize>
<TextAlign>Center</TextAlign>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<PaddingBottom>2pt</PaddingBottom>
</Style>
<ZIndex>6</ZIndex>
<Left>2.26406in</Left>
<Height>0.59063in</Height>
<Value>= "*" & Fields!ID.Value & "*" </Value>
</Textbox>
But the Scanner i have isn't reading it its not scanning it at all. Can any one help where is the error. Its a ID that gets to be printed and should be Scan able but its doesn't Scan. what other Font could Replace it ? It creates the BarCode looks fine prints and every thing Converts to PDF but doesn't Scan.
If your barcode ends in "62462", then all the bars and spaces that describe the previous characters are missing, including the initial "*" start symbol. In other words, the png file in the link above only shows the right hand side of the barcode, but I can't tell how much of the left or "start" of the barcode is cut off. I'm guessing the barcode is being clipped by some bounding rectangle.
Increase the width that you give the image generated by the textbox, and you may be okay.
When working with Code 3 of 9, the start and end of the barcode has a very distinctive look because of the asterisks on each side of the data. It looks like this:
If you work with Code 39 long enough, you'll recognize a code 39 barcode a mile away because of the symbol associated with the asterisks. Thin bar, thick space, then thin, thick, thick, thin bars separated by thin spaces.
How to turn off word wrap in iTerm2? Is there a specific command to do so or in the preferences? I am trying to avoid having the text run down to the next line. I would rather scroll side to side.
lifted directly from https://apple.stackexchange.com/a/210666/115119
Props to #michid
Disable line wrapping:
tput rmam
Enable line wrapping:
tput smam
It appears that iTerm2 does not have the ability to turn off word wrap. There is an open issue (iTerm2 issue #1790) reported to "Provide toggle to turn on/off line wrapping".
The description of that issue reads:
Looks like a conversation was had in the Google Groups about this but no one ever actually filed a feature request.
http://groups.google.com/group/iterm2-discuss/browse_thread/thread/e0f4e9b552d8acd4
In general I don't like having horizontal scrollbars and prefer to have the lines wrap, but there are occasions...such as looking at long stack traces, that I'd rather just have sequentially indented lines line up and just be forced to scroll to the right to expose all the details. To accomplish this task now, I end up making the text incredibly small so I can read stack traces lined up, but even that doesn't always work.
In October, 2014, the creator of iTerm2 commented regarding the feature request to toggle word wrap, "I'd like to do this but it's a lot of work, so feel free to send a pull request, but don't be [a jerk]."
In April, 2015, the milestone for the feature request was changed to "Future Release".
For me, my issue was purely down to the configuration of my PS1 - not what I had originally expected!
The key for me was surrounding the following with any characters that wouldn't be printed as in your prompt - such as encoding colours. Sourced from https://linoxide.com/how-tos/change-bash-prompt-variable-ps1/
\[ This sequence should appear before a sequence of characters that don’t move the cursor (like color escape sequences). This allows bash to calculate word wrapping correctly.
\] This sequence should appear after a sequence of non-printing characters.
I have a textbox and have to use the regular expressions in asp.net
My text should not allow the spaces in first and last place. In between words it can allow.
that means: it should allow alphabets, numbers and all special characters.
Output should be:
India Bangalore -valid
India Bangalore - not valid
!India bangalore - valid
India bangalore!##$%- valid
IndiaBangalore - valid
i.e : use can enter the spaces in between the words but not in first position and last position.
Java script also fine.
Thanks in advance.
Here is a quick example
// Input string
string st = " This is an example string. ";
// Call Trim instance method.
// This returns a new string copy.
st = st.Trim();
U can get the index, i mean index(0) is the first position of textbox and calculate the length of ur input +1 = last index of ur input validate white space validation now. damn sure it will work