It’s very complicated parsing a sentence for quotations!  However, I think I have now done it and can’t think of any further way to test it.

In CITESTYLE.php, uncomment line 165.
View a single resource.

I’ve provided some test $text for english and french (correct punctuation I think) in libs/CITE.php — play around with $text. You can change the style’s cite localization (I use a test style for this) to any localization but then need to change the punctuation (possibly apostrophes, possessives etc.) in $text as per CITELOC.php. It’s currently set up for in-text citation only as far as initial decisions on templates.

You will need to edit $text to ensure that a) the resource IDs in the cite tags are in your database and b) the author names in the text are those of the resource.

What happens:
After doing some tidying up of the initial text and converting quote marks to the selected localisation, this is then printed as ORIGINAL TEXT followed by TEXT AFTER PARSING AND REASSEMBLY (compiled after operations below).
Ellipses are protected from confusing punctuation rules as are Quotations and nested quotations are also marked up
The text is broken up into sentences and new paragraphs are marked.
Each sentence is parsed for cite tags and that information along with the citations resource variables are stored for each sentence.
Locations of citations’ creator appearance in the sentence is noted and the quotation prior to the citation is linked to the citation (important for breaking up the citation into e.g. “Grimshaw (2022) states “blah blah blah” (p.34).
Along the way, various decisions are made as to what type of citation template should be used (for in-text citations just now).
The $sentences array is now ready for mapping to the templates noted in each sentence's [‘citations’] array.


The end result is a printout of each sentence in the $sentences array, marked up, with its data ready for mapping to templates and producing the bibliographic list. e.g., 

>>>>>>
NEW SENTENCE:
startParagraph: 0
paragraphNumber: 1
sentence: This citation etc. with a reprint year and a page number, has the author's name—Everest and co-authors__W!K!NDX_CREATORS>0>W!K!NDX__—in the U.S.A. and U. S. S. R. sentence and quotes his famous saying: __W!K!NDX_STARTQUOTE>">0>W!K!NDX__U3RhcnROZXN0ZWRRdW90YXRpb24sIF9fVyFLIU5EWF9TVEFSVE5FU1RFRFFVT1RFPiI+VyFLIU5EWF9fbmVzdGVkJ3MgMV9fVyFLIU5EWF9FTkRORVNURURRVU9URT4iPlchSyFORFhfXyBfX1chSyFORFhfU1RBUlRORVNURURRVU9URT4iPlchSyFORFhfX25lc3RlZCAyX19XIUshTkRYX0VORE5FU1RFRFFVT1RFPiI+VyFLIU5EWF9fIEVuZE5lc3RlZFF1b3RhdGlvbg==__W!K!NDX_ENDQUOTE>">0>W!K!NDX__ [cite]33:101[/cite]. 
citations:
  0:  Array ( [citation] => [cite]33:101[/cite] [template] => followCreatorTemplate [resId] => 33 [pages] => 101 [juxtaposed] => 0 [resource] => Array ( [resourceId] => 33 [resourceType] => book [resourceTitle] => Acoustic Techniques for Home and Studio [resourceSubtitle] => [resourceNoSort] => [resourceIsbn] => [resourceField1] => [resourceField2] => 2 [resourceField3] => [resourceField4] => [resourceField5] => [resourceField6] => [resourceField7] => [resourceField8] => [resourceField9] => [resourceShortTitle] => [resourceTransTitle] => [resourceTransSubtitle] => [resourceTransShortTitle] => [resourceTransNoSort] => [resourceBibtexKey] => Everest1984 [resourceDoi] => [resourceTitleSort] => Acoustic Techniques for Home and Studio [resourceyearId] => 33 [resourceyearYear1] => 1984 [resourceyearYear2] => [resourceyearYear3] => [resourceyearYear4] => [resourcemiscId] => 33 [resourcemiscCollection] => [resourcemiscPublisher] => 4 [resourcemiscTag] => [resourcemiscEditUserIdResource] => [resourcemiscAddUserIdResource] => 1 [resourcemiscField1] => [resourcemiscField2] => [resourcemiscField3] => [resourcemiscField4] => [resourcemiscField5] => [resourcemiscField6] => [resourcemiscMaturityIndex] => [resourcemiscPeerReviewed] => N [resourcemiscQuarantine] => N [resourcemiscMetadata] => 0 [resourcepageId] => [resourcepagePageStart] => [resourcepagePageEnd] => ) [creators] => Array ( [0] => Array ( [surname] => Everest [firstname] => F. Alton [initials] => [prefix] => [creatorId] => 30 [resourcecreatorRole] => 1 ) ) [custom] => Array ( ) [url] => Array ( ) ) 
<<<<<<<

Explanation:
__W!K!NDX_CREATORS>0>W!K!NDX__ marks the location of an appearance of the citation creator’s name and which member of the [‘citations’] array it refers to.
__W!K!NDX_STARTQUOTE>">0>W!K!NDX__ . . . __W!K!NDX_ENDQUOTE>">0>W!K!NDX__ marks a quotation and which which member of the [‘citations’] array it refers to. In this case, the original $text had nested quote marks. Difficult and possibly buggy where close and end quote marks are the same, easier when they are not. The algorithm a) counts pairs of quote marks and ,b), if close and end quote marks are the same, if an odd-numbered quote mark has a space before it or not (taken to be a nested opening quote mark). Note that '>”>’ in __W!K!NDX_STARTQUOTE>">0>W!K!NDX__ and __W!K!NDX_ENDQUOTE>">0>W!K!NDX__ indicates the start and opening quote marks gathered from $text — this allows accurate reconstitution of the text at the end.
The [‘citations’] array contains all the citations in the sentence (with their resource and citeTag data [pages etc.]) and notes what kind of in-text citation template it should be. 


RULES:
Quotation marks must come in pairs. If there is any language that uses just one quotation mark before or after the quotation, well, we’ll cross that bridge when we come to it . . .
The citation picked up by the quotation markup is from the first citeTag after the quotation. This means such quotations must have their citeTags placed in such a position when writing the text. Most academic styles follow this but we must enforce it — the XML style defines afterwards if the citation can be broken up and moved around, but the citeTag must be in its expected position in order to match quotation to citeTag. If a quotation appears after a citeTag with no other citeTag in the sentence, then it is taken to be a free-standing quotation.
