Appendheader needs to append string, variable and then string again - json

Hopefully this is an easy one for someone out there. I need to append a long command that has strings and variables in it.
this->AppendHeader("Content-Range", "bytes " + offset "-" + (offset + part_size - 1) "/" + file_size);
This is not acceptable in C++. How can I format the above so the Header looks like
Content-Range: bytes 0-19/40
(just a fyi - offset is 0, part_size is 20 and file_size is 40)

Related

Why is isspace() returning false for strings from the docx python library that are empty?

My objective is to extract strings from numbered/bulleted lists in multiple Microsoft Word documents, then to organize those strings into a single, one-line string where each string is ordered in the following manner: 1.string1 2.string2 3.string3 etc. I refer to these one-line strings as procedures, consisting of 'steps' 1., 2., 3., etc.
The reason it has to be in this format is because the procedure strings are being put into a database, the database is used to create Excel spreadsheet outputs, a formatting macro is used on the spreadsheets, and the procedure strings in question have to be in this format in order for that macro to work properly.
The numbered/bulleted lists in MSword are all similar in format, but some use numbers, some use bullets, and some have extra line spaces before the first point, or extra line spaces after the last point.
The following text shows three different examples of how the Word documents are formatted:
Paragraph Keyword 1: arbitrary text
1. Step 1
2. Step 2
3. Step 3
Paragraph Keyword 2: arbitrary text
Paragraph Keyword 3: arbitrary text
• Step 1
• Step 2
• Step 3
Paragraph Keyword 4: arbitrary text
Paragraph Keyword 5: arbitrary text
Step 1
Step 2
Step 3
Paragraph Keyword 6: arbitrary text
(For some reason the first two lists didn't get indented in the formatting of the post, but in my word document all the indentation is the same)
When the numbered/bulleted list is formatted without line extra spaces, my code works fine, e.g. between "paragraph keyword 1:" and "paragraph keyword 2:".
I was trying to use isspace() to isolate the instances where there are extra line spaces that aren't part of the list that I want to include in my procedure strings.
Here is my code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
def extractStrings(file):
doc = file
for i in range(len(doc.paragraphs)):
str1 = doc.paragraphs[i].text
if "Paragraph Keyword 1:" in str1:
start1=i
if "Paragraph Keyword 2:" in str1:
finish1=i
if "Paragraph Keyword 3:" in str1:
start2=i
if "Paragraph Keyword 4:" in str1:
finish2=i
if "Paragraph Keyword 5:" in str1:
start3=i
if "Paragraph Keyword 6:" in str1:
finish3=i
print("----------------------------")
procedure1 = ""
y=1
for x in range(start1 + 1, finish1):
temp = str((doc.paragraphs[x].text))
print(temp)
if not temp.isspace():
if y > 1:
procedure1 = (procedure1 + " " + str(y) + "." + temp)
else:
procedure1 = (procedure1 + str(y) + "." + temp)
y=y+1
print(procedure1)
print("----------------------------")
procedure2 = ""
y=1
for x in range(start2 + 1, finish2):
temp = str((doc.paragraphs[x].text))
print(temp)
if not temp.isspace():
if y > 1:
procedure2 = (procedure2 + " " + str(y) + "." + temp)
else:
procedure2 = (procedure2 + str(y) + "." + temp)
y=y+1
print(procedure2)
print("----------------------------")
procedure3 = ""
y=1
for x in range(start3 + 1, finish3):
temp = str((doc.paragraphs[x].text))
print(temp)
if not temp.isspace():
if y > 1:
procedure3 = (procedure3 + " " + str(y) + "." + temp)
else:
procedure3 = (procedure3 + str(y) + "." + temp)
y=y+1
print(procedure3)
print("----------------------------")
del doc
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
import docx
doc1 = docx.Document("docx_isspace_experiment_042420.docx")
extractStrings(doc1)
del doc1
Unfortunately I have no way of putting the output into this post, but the problem is that whenever there is a blank line in the word doc, isspace() returns false, and a number "x." is assigned to empty space, so I end up with something like: 1. 2.Step 1 3.Step 2 4.Step 3 5. 6. (that's the last iteration of print(procedure3) from the code)
The problem is that isspace() is returning false even when my python console output shows that the string is just a blank line.
Am I using isspace() incorrectly? Is there something in the string I am not detecting that is causing isspace() to return false? Is there a better way to accomplish this?
Use the test:
# --- for s a str value, like paragraph.text ---
if s.strip() == "":
print("s is a blank line")
str.isspace() returns True if the string contains only whitespace. An empty str contains nothing, and so therefore does not contain whitespace.

SSIS Derived Column Transformation

I am trying to develop a package which takes a string (in the format 1.02.3.04 or 01.02.03.4 and lots of other permutations) and amends this based upon the following rules
if the second character is a "." then pad the first group with a 0
FINDSTRING([mycolname],".",1) returns the position of the first "." and for all values of 2 then apply this rule and amend the string eg if 1.2.3.4 will return 2 the string should be 01.2.3.4
if the second instance of "." is 5 FINDSTRING([mycolname],".",2) then add a 0 in after the third character eg 01.02.3.4
if the third instance of "." is 8 FINDSTRING([mycolname],".",3) then add 0 in after the 6th character
I am a little stuck with some of the logic !
anyone help ??
in SSIS 2012 can be achieved with a one-liner Derived Column:
RIGHT("00" + TOKEN("1.02.3.04",".",1),2) + "." + RIGHT("00" + TOKEN("1.02.3.04",".",2),2) + "." + RIGHT("00" + TOKEN("1.02.3.04",".",3),2) + "." + RIGHT("00" + TOKEN("1.02.3.04",".",4),2)

Validation/Format of display-name in from header

I need to know what are the rules for validation/format from(name-addr) field in the email.
In rfc explained the format of name-addr, but goes into detail about the display-name.
Like this:
From: John Q. Public <JQP#bar.com>
I want to know the characters and length allowed.
How do I know that John Q. Public has valid characters?
Should I allow only printable US-ASCII characters ?
I consulted the RFC 2822 and not found on the specific format of a display name
This is all defined in the rfc you linked to in your question (btw, the newer version of this document is RFC 5322):
display-name = phrase
phrase = 1*word / obs-phrase
word = atom / quoted-string
atom = [CFWS] 1*atext [CFWS]
atext = ALPHA / DIGIT / ; Any character except controls,
"!" / "#" / ; SP, and specials.
"$" / "%" / ; Used for atoms
"&" / "'" /
"*" / "+" /
"-" / "/" /
"=" / "?" /
"^" / "_" /
"`" / "{" /
"|" / "}" /
"~"
specials = "(" / ")" / ; Special characters used in
"<" / ">" / ; other parts of the syntax
"[" / "]" /
":" / ";" /
"#" / "\" /
"," / "." /
DQUOTE
You have to jump around in the document a bit to find the definitions of each of these token types, but they are all there.
Once you have the definitions, all you need to do is scan over your name string and see if it consists only of the valid characters.
According to the definitions, a display-name is a phrase and a phrase is 1-or-more word tokens (or an obs-word which I'll ignore for now to make this explanation simpler).
A word token can be either an atom or a quoted-string.
In your example, John Q. Public contains a special character, ".", which cannot appear within an atom token. What about a quoted-string token? Well, let's see...
quoted-string = [CFWS]
DQUOTE *([FWS] qcontent) [FWS] DQUOTE
[CFWS]
qcontent = qtext / quoted-pair
qtext = NO-WS-CTL / ; Non white space controls
%d33 / ; The rest of the US-ASCII
%d35-91 / ; characters not including "\"
%d93-126 ; or the quote character
Based on this, we can tell that a "." is allowed within a quoted-string, so... the correct formatting for your display-name can be any of the following:
From: "John Q. Public" <JQB#bar.com>
or
From: John "Q." Public <JQB#bar.com>
or
From: "John Q." Public <JQB#bar.com>
or
From: John "Q. Public" <JQB#bar.com>
Any one of those will work.

plugin for formatting comments

Can anyone point me in the direction of a plugin or otherwise for formatting comments?
I'm using coffeescript, commenting is the same as python (#line, ### block ###), although javascript commenting also passes straight through the compiler.
OK, turns out that Edit -> Wrap keeps comments intact - complete newby.
There is also https://github.com/spadgos/sublime-jsdocs
I don't have a plug-in but I can offer a python script that I wrote. Enter your comment as a string at the 'user entered comment' (uec) variable, save and run. It will format a block quote surrounded by pound signs 80 characters across. If you need your block quote shorter or longer then just change the 80, the 78, and the 76.
def first2lines(): return str(('#' * 80) + '\n' + '#' + (' ' * 78) + '#') # first two lines
def leftSide(): return '# ' # left side of border
def rightSide(): return ' #' # right side of border
def last2lines(): return str('#' + (' ' * 78) + '#' + '\n' + ('#' * 80)) # last two lines
# user entered comment
uec = "This program will neatly format a programming comment block so that it's surrounded by pound signs (#). It does this by splitting the comment into a list and then concatenating strings each no longer than 76 characters long including the correct amount of right side space padding. "
if len(uec) > 0:
eosm = '<<<EOSM>>>' # end of string marker
comment = uec + ' ' + eosm
wordList = comment.split() # load the comment into a list
tmpString = '' # temporarily holds loaded elements
loadComment = '' # holds the elements that will be printed
counter = 0 # keeps track of the number of elements/words processed
space = 0 # holds right side space padding
last = wordList.index(wordList[-1]) # numerical position of last element
print first2lines()
for word in wordList:
tmpString += word + ' ' # load the string until length is greater than 76
# processes and prints all comment lines except the last one
if len(tmpString.rstrip()) > 76:
tmpList = tmpString.split()
tmpString = tmpList[-1] + ' ' # before popping last element load it for the beginning of the next cycle
tmpList.pop()
for tmp in tmpList:
loadComment += tmp + ' '
loadComment = loadComment.rstrip()
space = 76 - len(loadComment)
print leftSide() + loadComment + (space * ' ') + rightSide()
loadComment = ''
# processes and prints the last comment line
elif len(tmpString.rstrip()) <= 76 and counter == last:
tmpList = tmpString.split()
tmpList.pop()
for tmp in tmpList:
loadComment += tmp + ' '
loadComment = loadComment.rstrip()
space = 76 - len(loadComment)
print leftSide() + loadComment + (space * ' ') + rightSide()
counter += 1
print last2lines()
else:
print first2lines()
print leftSide() + "The length of your comment is zero, it must be at least one character long. " + rightSide()
print last2lines()
You can use netbeans, it has autoFormatting Alt+Mayus+F

AS3 Warning message excess bytes

When I publish my flash files, I get this message:
WARNING: excess bytes: -616, Tag: DefineFont3, Index: 5
WARNING: excess bytes: 2, Tag: DefineFont3, Index: 36
What are these warning? Anything related to these warning?
Yesterday is still fine, but today I get this.
Maybe one of your libraries are using the SWFTimeline. It's source code contains the very same warning.
The following code snippet is from the SWFTimeline.as file, starting at line 84.
// Adjust position (just in case the parser under- or overflows)
if(data.position != pos + tagHeader.tagLength) {
trace("WARNING: excess bytes: " +
(data.position - (pos + tagHeader.tagLength)) + ", " +
"Tag: " + tag.name + ", " +
"Index: " + (tags.length - 1)
);
data.position = pos + tagHeader.tagLength;
}
It seens to be caused by malformed tags or file corruptions, maybe other reasons too.